I have a doubt with the switch statement.
A switch's expression must evaluate to a char, byte, short, int, or, as of
Java
6, an enum.
& 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.
Now why does the below statement fails ??
final int a = 1;
final int b;
b = 2;
int x = 0;
switch (x) {
case a: // ok
case b: // compiler error
If I put SOUT statement below line (b=2), Value of b is printed as '2'.
then why doesn't switch statement accept it??