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 Case expressions on a switch statement 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 "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’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: Case expressions on a switch statement
 
It's not a secret anymore!