5.8.2.Case constant must be a compile time constant!
It is not enough to be final, it must be a compile time constant.
public class MainClass{ public static void main(String[] argv){ final int a = 1; final int b;
b = 2; int x = 0; switch (x) { case a: // ok case b: // compiler error
}
}
}
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
case expressions must be constant expressions
at MainClass.main(MainClass.java:9)