大小写表达式必须是静态 final int 的常量表达式?
2022-09-04 00:55:58
我有一个定义: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
这是怎么回事?