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.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes what is compile time constant in switch case? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "what is compile time constant in switch case?" Watch "what is compile time constant in switch case?" New topic
Author

what is compile time constant in switch case?

aslika bahini
Ranch Hand

Joined: Mar 03, 2007
Posts: 111


Hi,
what is compile time constant in switch case?




why the above code doesn't work?

Thanks!
regards
samura


Juwonlo Ibigbami
Ranch Hand

Joined: Nov 03, 2006
Posts: 83
code:
---------------------------------------------------------------------------

final int a =1;
final int b;
b = 2;
int x =0;
switch(x)
case a: //ok
case b: //compiler error

---------------------------------------------------------------------------

your variable a and b should be a constant and should be declear as final ans static with iniialised value
 
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
 
subject: what is compile time constant in switch case?
 
It's not a secret anymore!