This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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 Murach's Java Servlets and JSP this week in the Servlets 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!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
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