[enhanced-switches] My experience of converting old switches to new ones

Remi Forax forax at univ-mlv.fr
Mon Sep 19 08:07:04 UTC 2022


----- Original Message -----
> From: "Tagir Valeev" <amaembo at gmail.com>
> To: "Brian Goetz" <brian.goetz at oracle.com>
> Cc: "amber-spec-experts" <amber-spec-experts at openjdk.java.net>
> Sent: Monday, September 19, 2022 9:22:34 AM
> Subject: Re: [enhanced-switches] My experience of converting old switches to new ones

> Hello!
> 
>> > We need total switch statements.
>>
>>
>> Is this different from the "default impossible" above?
> 
> Yes. I mean, currently we cannot have exhaustiveness checks on enum
> switch statements having a compilation error when a new enum constant
> is added. We have this for switch expressions and for sealed classes,
> but not for switch statements over enums.

enum Foo { A, B }

switch(foo) {
  case null -> throw null;
  case A -> ...
  case B -> ...
}

is exhaustive.  

> 
> With best regards,
> Tagir Valeev.

Rémi


More information about the amber-spec-experts mailing list