I think the problem might be that you are declaring the variables as final, if you want to give them values anywhere in the code except on declaration, I would suggest you don't make them final, just and then you can say It should work.
Declaring a variable with the final keyword makes it impossible to reinitialize that variable once it has been initialized with an explicit value (notice we said explicit rather than default). For primitives, this means that once the variable is assigned a value, the value can't be altered. For example, if you assign 10 to the int variable x, then x is going to stay 10, forever.
K&B BOOK PG 57.
So does this mean that without initialization, the final variable in the above source gets the value 0 assigned automatically, since its the default for primitves(here int), and receives the ability to modify it later
A compile-time constant expression is an expression denoting a value of primitive type or a String that is composed using only the following:
Literals of primitive type and literals of type String
Casts to primitive types and casts to type String
The unary operators +, -, ~, and ! (but not ++ or --)
The multiplicative operators *, /, and %
The additive operators + and -
The shift operators <<, >>, and >>>
The relational operators <, <=, >, and >= (but not instanceof)
The equality operators == and !=
The bitwise and logical operators &, ^, and |
The conditional-and operator && and the conditional-or operator ||
The ternary conditional operator ? :
Simple names that refer to final variables whose initializers are constant expressions
Qualified names of the form TypeName . Identifier that refer to final variables whose initializers are constant expressions
I think I misunderstood your question a bit the first time, I think in the case of switch trapping, the case must always have a constant value because it bases itself on a certain condition that must not change in the loop. so the the variable in the case must be a constant.
Actually here 2 situations may arise:
1) local variable is final and not initialized before using it in switch , as it is method variable it must be initialized,
Compiler says something like this " variable xxx might not have been initialized"
2) local variable is final and initialized before using in switch (i.e declaration and initialization is done in different statements),
Compiler says something like this "constant expression is required"
Now my question is , why there is second type of error if the first situation alone can handle both the cases...