What is the difference between final variables and compile time constants?
Consider the following code
final int a = 5;
final int b;
b=6;
int x=0;
switch
The problem is, that all case:
statements must be ultimate at compile time.
Your first statement is ultimate. a
will for 100% be no other value than 5
.
final int a = 5;
However, this is not guaranteed for b
. What if there would be an if-statement around b
?
final int b;
if(something())
b=6;
else
b=5;