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 Case expressions on a switch statement 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 "Case expressions on a switch statement" Watch "Case expressions on a switch statement" New topic
Author

Case expressions on a switch statement

O. Ziggy
Ranch Hand

Joined: Oct 02, 2005
Posts: 430



output:



The above code example has confused me. I thought that case expressions can only be compile time constants. Is (byte)c+2 a compile time constant?
Sebanti Sanyal
Ranch Hand

Joined: Nov 07, 2011
Posts: 58

Yes it is, since 'c' itself is a compile time constant declared with the 'final' keyword and initialized at the same time.
O. Ziggy
Ranch Hand

Joined: Oct 02, 2005
Posts: 430

I thought a compile time constant is one that is declared as a literal or a public static final field. I didnt know that an expression can result in a compile time constant.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Case expressions on a switch statement
 
Similar Threads
Compile Time Constant
Switch- Case doubt in case expressions.
Automatic typecasting
Switch case Compiler error
Legal arguments in switch case statements