I have the following code:
public class Main {
static final String fu = Week.class.getName();
public static void main(String[] arg0){
String h = "dummy";
switch (h) {
* case fu:
System.out.println(8);
break;
default:
break;
}
}
}
Now Eclipse complains at * that case expressions must be constant expressions
. But I made fu
as constant as I know to do! Why is this not enough, what can I do (other than if-else)?
Why is this not enough
Because it's not a compile-time constant by the rules of JLS 15.28.
Why is this not enough, what can I do (other than if-else)?
Nothing, basically - unless you use a string literal, which would obviously not be very pleasant.
See more on this question at Stackoverflow