Call for feedback -- enhanced switch

Jorn Vernee jbvernee at xs4all.nl
Sun Mar 24 17:55:48 UTC 2019


Actually, I just realized that there is no `// automatic exception` 
because this is not an expression switch :) If I remove the println to 
make it compile I get:

```
       24: lookupswitch  { // 2
                      1: 52
                      2: 58
                default: 61
           }
       52: iload_1
       53: istore        4
       55: goto          61
       58: iload_2
       59: istore        4
       61: return
```
(i.e. no exception)

I guess this further proves my point that existence of automatic default 
can be confusing...

Jorn

Remi Forax schreef op 2019-03-24 18:49:
> ----- 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