Call for feedback -- enhanced switch

Remi Forax forax at univ-mlv.fr
Sun Mar 24 17:49:59 UTC 2019


----- Mail original -----
> De: "Jorn Vernee" <jbvernee at xs4all.nl>
> À: "Brian Goetz" <brian.goetz at oracle.com>
> Cc: "amber-dev" <amber-dev at openjdk.java.net>
> Envoyé: Dimanche 24 Mars 2019 17:17:28
> Objet: Re: Call for feedback -- enhanced switch

> Hi,
> 

[...]

> * Also, maybe a bug:
>     ```
>     enum MyEnum {
>         X, Y;
>     }
>     public static void main(String[] args) throws Throwable {
>         int x = 5;
>         int y = 10;
>         MyEnum myEnum = MyEnum.X;
>         int o;
>         switch(myEnum) {
>             case X -> o = x;
>             case Y -> o = y;
>             // automatic exception
>         };
>         System.out.println(o);
>     }
>     ```
>   Even though the switch should be exhaustive, javac complains that 'o'
> might not have been initialized.

yes, it's a bug. And ecj has the same issue :(

> 
> Cheers,
> Jorn

regards,
Rémi

> 
> Brian Goetz schreef op 2019-03-01 22:55:
>> We would like to promote enhanced switch to a permanent feature in
>> Java 13.  So far, the only change we are anticipating is:
>> 
>>     - change “break value” to “break-with value”.
>> 
>> This is the time for people to try it out on their codebases (there’s
>> even refactoring support in IDEA!) and provide feedback on what works,
> > what doesn’t, and what was surprising.


More information about the amber-dev mailing list