• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

what can be passed to case statement?

 
adam Lui
Ranch Hand
Posts: 186
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry if this is such a stupid question, but i am really confused.
 
Burkhard Hassel
Ranch Hand
Posts: 1274
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Howdy,

because the switch statement takes only ints (or lower) and enums,
this is true also for the case statement. Additionally the case statement has to be a compile time constant, e.g. a int literal. And enum values are per se compile time constants:




The last three are not really planets.
The x as an int is allowed, because it is a compile time constant small enough to fit in a short.

By the way, as types smaller as ints are allowed, the switch case thing also works with chars (but not with Character...).

Yours,
Bu.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic