CSR :
|
|
Relates :
|
|
Relates :
|
|
Relates :
|
Summary ------- Extend the switch statement so that it can be used as either a statement or an expression, and so that both forms can use either a traditional `case :` label (with fall through) or a simplified `case ->` label (no fall through). Problem ------- Several irregularities of the switch statement have long been an irritation to users, and impediments to support for features like pattern matching. These irregularities include (i) the default control flow behavior (fall through) of switch blocks, (ii) the default scoping of switch blocks (the block is treated as one single scope), and (iii) the fact that switch works only as a statement, even though it is commonly more natural to express multi-way conditionals as expressions. Solution -------- The JLS will be enhanced with support for: - `switch` expressions - in `switch` expressions and `switch` statements, a choice between switch labeled rules (`case ->`) and switch labeled statement groups (`case :`). - in `switch` expressions and `switch` statements, the ability to have multiple constants in a case label. - in `switch` expressions, the introduction of a _value `break` statement_ to yield a result from the switch expression. These features, as a group, will constitute a _preview feature_ ([JEP 12](http://openjdk.java.net/jeps/12)) in Java SE 12. Specification ------------- Proposed changes to the JLS are attached to this CSR. The changes are also available at http://cr.openjdk.java.net/~gbierman/switch-expressions-2019-01.html. There are no changes to the JVMS.
|