This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
case expressions must be constant expressions , and in given code b is blank final variable , sa at compile time compiler checks the constant expression for case statement, and b get value 2 at run time
There is a difference between 'a' and 'b'. 'a' is initialized with a compile-time constant expression and is final. So we call it 'a constant variable'. 'b' is final but it is blank final variable. A blank final is a final variable whose declaration lacks an initializer.
That's why you cannot use 'b' in the way you are trying to use it.