Hi ,
Could anyone explain me the meaning of the following:
A case constant must evaluate to the same type as the switch expression can
use, with one additional—and big—constraint: the case constant must be a
compile time constant! Since the case argument has to be resolved at compile
time, that means you can use only a constant or final variable that is assigned a
literal value. It is not enough to be final, it must be a compile time constant. For
example:
final int a = 1;
final int b;
b = 2;
int x = 0;
switch (x) {
case a: // ok
case b: // compiler error
I didn't get it.
Thanks
Aditya Sharma