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).
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.
SolutionThe JLS will be enhanced with support for:
switch
expressionsswitch
expressions and switch
statements, a choice between switch labeled rules (case ->
) and switch labeled statement groups (case :
).switch
expressions and switch
statements, the ability to have multiple constants in a case label.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) in Java SE 12.
SpecificationProposed 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.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4