Meaningless Drivel is fun!*
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
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 agree. Here's the link: http://aspose.com/file-tools
 
subject: what is compile time constant in switch case?
 
Similar Threads
switch question
switch statement and compile time constatns.
Doubt about Switch statement (Compile Time Constant)
compile time constant
Compile Time constant??