switch with several arguments

Remi Forax forax at univ-mlv.fr
Wed Dec 13 10:25:47 UTC 2017


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-experts mailing list