switch with several arguments
Remi Forax
forax at univ-mlv.fr
Wed Dec 13 14:45:44 UTC 2017
Technically, you do not need tuples/value types because you push the value,
matching on several arguments is already something that need to be supported when destructuring because you need to match all the arguments of the result of a call to the destructor.
Anyway , at least, we have to check that the meta protocol will allow such extension.
Rémi
I'm typing this in the movie theater waiting for last star wars, if you do not agree, I will tell you how it's ends.
On December 13, 2017 2:43:00 PM GMT+01:00, Gavin Bierman <gavin.bierman at oracle.com> wrote:
>You’ll not be surprised to hear that we’ve thought about it. It is
>certainly a very cool extension and makes for some very slick code.
>Personally I think it should wait until we have thought about tuples
>more generally (which might well be part of a value types enhancement).
>
>Gavin
>
>> On 13 Dec 2017, at 10:25, Remi Forax <forax at univ-mlv.fr> wrote:
>>
>> Should we support a switch with several arguments ?
>>
>> By example:
>> for(int i = 1; i < 100; i++) {
>> System.out.println(
>> switch(i % 3, i % 5) {
>> case (0, 0) -> "FizzBuzz";
>> case (0, _) -> "Fizz";
>> case (_, 0) -> "Buzz";
>> default -> i;
>> });
>> }
>>
>> Apart FizzBuzz, it's very convenient when you want to merge things,
>take decision depending on more than one value.
>>
>> Note that this example also use the "locals do not need to be
>effectively final" semantics.
>>
>> Rémi
--
Sent from my Android device with K-9 Mail. Please excuse my brevity.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openjdk.java.net/pipermail/amber-spec-experts/attachments/20171213/36c40aaa/attachment.html>
More information about the amber-spec-experts
mailing list