New JEP: Switch Expressions for the Java Language

Liam Miller-Cushon cushon at google.com
Thu Dec 7 23:28:44 UTC 2017


I don't see it mentioned in the JEP, but will the default case of an
expression switch be required to be last? (Previously:
http://mail.openjdk.java.net/pipermail/amber-spec-observers/2017-November/000134.html
)

> in the case of an enum switch that covers all known cases, a default
clause can be inserted by the compiler that indicates that the enum
definition has changed between compile time and runtime

This sounds great, but note that it makes adding values to an enum a
potentially source-incompatible change. Pattern switches that handle all
values of an enum will need to be updated to handle the new value, or to
have an explicit default.

In our code base we use static analysis to require statement switches on
enums either handle all values or have a default. The issue with source
incompatibility and adding values to enums hasn't been a significant
problem so far.


On Thu, Dec 7, 2017 at 2:33 PM, Brian Goetz <brian.goetz at oracle.com> wrote:

> We've separated out a package of standalone improvements to `switch`
> (switch expressions, case null, and case alternation) into their own JEP:
>
>     https://bugs.openjdk.java.net/browse/JDK-8192963
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openjdk.java.net/pipermail/amber-spec-experts/attachments/20171207/4f6e884c/attachment.html>


More information about the amber-spec-experts mailing list