I have a final class Ring
defined as:
final class Ring {
public static final int OUT = 3;
public static final int MID = 2;
public static final int IN = 1;
}
I also have a public class MorrisBoard
with the following code:
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
references a variable which is immutable for the lifetime of the program. All values are final.
However, I still get the following error: case expressions must be constant expressions
. I'm confused by this - MorrisBoard.RING.OUT
is a constant expression.
What is going on here?