JEP proposed to target JDK 17: 406: Pattern Matching for switch (Preview)
Mike Rettig
mike.rettig at gmail.com
Fri May 21 13:22:37 UTC 2021
On Fri, May 21, 2021 at 2:07 AM Remi Forax <forax at univ-mlv.fr> wrote:
> ----- Mail original -----
> > De: "Mike Rettig" <mike.rettig at gmail.com>
> > Will non-expression switches be exhaustive? I know that this has been
> > discussed but I wanted to confirm the behavior for jdk 17.
> >
> >
> https://mail.openjdk.java.net/pipermail/amber-spec-experts/2021-April/002959.html
> >
> > Sealed classes will be far more useful with exhaustiveness.
>
> yes,
> see 15.28.1 of the current spec [1].
15.28.1 is specifically referring to switch expressions. I am asking about
the non-expression form.
Will this switch compile even though it is not exhaustive?
abstract sealed class Shape {...}
... class Circle extends Shape {...}
... class Rectangle extends Shape {...}
Shape s = ....
switch(s){
case Circle c ->{handleCircle(c);}
//no case for Rectangle or default
}
More information about the jdk-dev
mailing list