我有一个final class Ring
定义为:
final class Ring {
public static final int OUT = 3;
public static final int MID = 2;
public static final int IN = 1;
}
我也有public class MorrisBoard
以下代码:
public class MorrisBoard {
public static final Ring RING = new Ring();
private boolean checkMillBy(int ring, int x, int y) {
switch(ring) {
case MorrisBoard.RING.OUT:
//...
case MorrisBoard.RING.MID: //etc.
//...
}
return false;
}
MorrisBoard.RING.OUT
引用一个在程序生命周期内不可变的变量。所有值都是最终值。
但是,我仍然收到以下错误:case expressions must be constant expressions
. 我对此感到困惑 -MorrisBoard.RING.OUT
是一个常量表达式。
这里发生了什么?