Call for feedback -- enhanced switch
forax at univ-mlv.fr
forax at univ-mlv.fr
Sun Mar 24 18:00:37 UTC 2019
----- Mail original -----
> De: "Jorn Vernee" <jbvernee at xs4all.nl>
> À: "Remi Forax" <forax at univ-mlv.fr>
> Cc: "Brian Goetz" <brian.goetz at oracle.com>, "amber-dev" <amber-dev at openjdk.java.net>
> Envoyé: Dimanche 24 Mars 2019 18:55:48
> Objet: Re: Call for feedback -- enhanced switch
> 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...
hum, this one still doesn't work !
enum MyEnum {
X, Y;
public static void main(String[] args) {
MyEnum myEnum = MyEnum.X;
int o;
var f = switch(myEnum) {
case X -> o = 5;
case Y -> o = 10;
// automatic exception
};
System.out.println(o);
}
}
>
> Jorn
Rémi
>
> 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