switch with several arguments
Gavin Bierman
gavin.bierman at oracle.com
Wed Dec 13 13:43:00 UTC 2017
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
More information about the amber-spec-observers
mailing list