aspose file tools*
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.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Case expressions on a switch statement