[External] : Re: Rehabilitating switch -- a scorecard

Brian Goetz brian.goetz at oracle.com
Mon May 17 22:23:10 UTC 2021

>     I think we've done a remarkable job at rehabilitating this monster. 
> I believe the only pending issue on that matter is the position of 
> default inside the switch,
> With the legacy switch, default can be in the middle, with a switch on 
> types that default has to be the last case.
> I think we should try to emit a warning if "default" is not at last 
> position, both Eclipse and IntelliJ already have that warning.

In an earlier round, we pended this issue because there were corner 
cases such as default falling into another case, such as:

     switch (n) {
         case 1: println("one"); break;
         case 2: println("two"); break;
         default: print("more than ");
         case 3: println("three"); break;

which prints "one", "two", "three", or "more than three".

This is legal, if silly.  We pended this issue until the rest of the 
story shook out; now that it has, I think we are still kind of in the 
same place here.  A warning is OK here but it feels more like a style 
hint than  a real warning.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.java.net/pipermail/amber-spec-experts/attachments/20210517/5d5ef0d7/attachment-0001.htm>

More information about the amber-spec-experts mailing list