• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Case expressions on a switch statement

 
O. Ziggy
Ranch Hand
Posts: 430
Android Debian VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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
Posts: 58
C++ Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 430
Android Debian VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic