File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes what can be passed to case 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 "what can be passed to case statement?" Watch "what can be passed to case statement?" New topic

what can be passed to case statement?

adam Lui
Ranch Hand

Joined: Sep 03, 2007
Posts: 186
sorry if this is such a stupid question, but i am really confused.
Burkhard Hassel
Ranch Hand

Joined: Aug 25, 2006
Posts: 1274

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...).


all events occur in real time
I agree. Here's the link:
subject: what can be passed to case statement?
It's not a secret anymore!