What I knew up to now about switch/case construct:
1�) the variable x in switch(x) must be either byte, short, char or int
. It must not be long, either of the floating-point types, boolean, or an object reference.
2�) The arguments to case labels must be compile constant expression
according to JLS 15.28:
# Simple names that refer to final variables whose initializers are constant expressions
# Qualified names of the form TypeName . Identifier that refer to final variables whose initializers are constant expressions
3�) What I've just learned from Bill Brogden's Questions is that the type used in the switch statement must accommodate all of the values in the case statements
Thus, this will not compile:
because of lines 2 and 3 in which range > 127.
But this wil compile with success:
Maybe it's worth knowing this...
SCJP 1.4, SCWCD, SCBCD, IBM XML, IBM Websphere 285, IBM Websphere 287