Name: rmT116609 Date: 02/03/2003
DESCRIPTION OF THE PROBLEM :
The Java 'switch' statement should be made into less of a special-case implementation oriented construct and more into a general-purpose multi-way branch construct that isn't tied down by its implementation. The very basic
changes to get there include:
- Drop the requirements that case labels be constants. Allow them to be arbitrary expressions, and specify that cases are evaluated in textual order in case the expressions have side effects.
- Extend the types allowable in case labels to include long, and to include reference types. Reference typed cases would be evaluated for a match under these rules:
If the variable and case label value are both null, then a match occurs. If only one of the two is null, then no match occurs. If neither is null and var.equals(lab) is true (where var is the variable and lab is the label
expression) then a match occurs. Else, no match occurs.
This proposal would allow use of cases in plenty of situations where if/else chains are currently required.
No Java VM changes are proposed in this RFE. The change is to the language-level switch construct, NOT the bytecode tableswitch and lookupswitch instructions. Those instructions could still be used to implement certain
switch statements that are expressable in terms of their behavior.
CUSTOMER WORKAROUND :
Chained if/else statements can be used to provide the same control flow, but at a reduced level of readability.
(Review ID: 163356)