Pattern Matching for switch (Second Preview)

forax at univ-mlv.fr forax at univ-mlv.fr
Sun Sep 26 11:13:36 UTC 2021


> From: "Tagir Valeev" <amaembo at gmail.com>
> To: "Remi Forax" <forax at univ-mlv.fr>
> Cc: "Brian Goetz" <brian.goetz at oracle.com>, "Tesla Ice Zhang"
> <ice1000kotlin at foxmail.com>, "jan lahoda" <jan.lahoda at oracle.com>, "amber-dev"
> <amber-dev at openjdk.java.net>
> Sent: Dimanche 26 Septembre 2021 04:44:44
> Subject: Re: Pattern Matching for switch (Second Preview)

> Hello!

> вс, 26 сент. 2021 г., 2:36 < [ mailto:forax at univ-mlv.fr | forax at univ-mlv.fr ] >:

>> >> It's not exactly the same semantics because "Object e" allows null while
>> >> "default" don't.

>> > The semantics more more different than that; because default has special
>> > prvileges with respect to ordering. Bottom line: don't use default in
>> > pattern switch, use real patterns.

>> yes very true,
>> I would love to have javac to emit a warning if default is not the last case
>> (for all switches).

> Probably, it should be a compilation error for all non-legacy switches, like we
> require totality for non-legacy switches? I don't think that ability to place
> default in non-last case brings any profit for programmers. It only adds
> confusion.

yes, i agree. 

> With best regards,
> Tagir Valeev

regards, 
Rémi 


More information about the amber-dev mailing list