Meaningless Drivel is fun!*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes switch statement and compile time constatns. 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 "switch statement and compile time constatns." Watch "switch statement and compile time constatns." New topic
Author

switch statement and compile time constatns.

Jan Osykowski
Ranch Hand

Joined: Jul 15, 2010
Posts: 41
Hey guys,

I have a question about the switch construction. In the book it's written that the case constant must be a compile time constant and thus i have a question to this code:



And it works but I think that b+ 2*b is not a compile time constant. What do you think? On the other hand this code doesn't work:



Why it's like this?

Cheers,
Jan.
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Actually, if you mix your compile time constant with non-compile time constant then result become non-compile time constant

Malatesh Karabisti
Ranch Hand

Joined: Jul 28, 2010
Posts: 153

Compile time constant will be formed only with Rules
Jan Osykowski
Ranch Hand

Joined: Jul 15, 2010
Posts: 41
Alright, thanks for the answers!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: switch statement and compile time constatns.
 
Similar Threads
what is compile time constant in switch case?
final variables
Compile Time Constant
Doubt about Switch statement (Compile Time Constant)
compile time constant