New JEP: Switch Expressions for the Java Language

forax at univ-mlv.fr forax at univ-mlv.fr
Fri Dec 8 14:59:44 UTC 2017


----- Mail original -----
> De: "Brian Goetz" <brian.goetz at oracle.com>
> À: "Remi Forax" <forax at univ-mlv.fr>
> Cc: "amber-spec-experts" <amber-spec-experts at openjdk.java.net>
> Envoyé: Vendredi 8 Décembre 2017 15:48:36
> Objet: Re: New JEP: Switch Expressions for the Java Language

> Clearly accessing locals should be allowed, to some degree -- it would
> be weird if we could not reference y here.  But it is reasonable to ask,
> what restrictions do we want to place? 

yes,

> Are the same restrictions as lambdas -- effectively-final only -- too restrictive? 

I believe it's ok to have the same restrictions as lambdas.
We still have the classical switch as backup and given that the current proposed syntax uses '->', it will be weird if expression/body after the -> has another set of rules as the lambda ones.

> (Certainly such a restriction opens up more options for translation strategies, and is
> consistent with other -> contexts.)

yes, if the expression switch as the same restrictions as a lambda expression/body, it means we can represent each expression as a static method like with the lambda translation instead of having one blob of code for all expressions, so we can re-organise them, not even make one of them present if the case is never called, etc.

Rémi

> 
> On 12/7/2017 6:02 PM, Remi Forax wrote:
>> Hi Brian,
>> correct me of i'm wrong but there is no discussion about accessing to a local
>> variable in the body of an expression,
>>
>> void m(int x, int y) {
>>    return switch(x) {
>>      case 0 -> y;   // is it allowed, how is it translated ?
>>      default -> 0;
>>    };
>> }
>>
>> regards,
>> Rémi
>>
>> ----- Mail original -----
>>> De: "Brian Goetz" <brian.goetz at oracle.com>
>>> À: "amber-spec-experts" <amber-spec-experts at openjdk.java.net>
>>> Envoyé: Jeudi 7 Décembre 2017 23:33:36
>>> Objet: New JEP: Switch Expressions for the Java Language
>>> We've separated out a package of standalone improvements to `switch`
>>> (switch expressions, case null, and case alternation) into their own JEP:
>>>
> >>       https://bugs.openjdk.java.net/browse/JDK-8192963


More information about the amber-spec-experts mailing list