I agree with Kevin, case pat1 -> case pat2 -> s is too close to case pat1 -> pat2 -> s which has a very different meaning (the result is a lambda).
Rémi > De: "Kevin Bourrillion" <[email protected]> > À: "Guy Steele" <[email protected]> > Cc: "amber-spec-experts" <[email protected]> > Envoyé: Lundi 23 Avril 2018 20:02:30 > Objet: Re: JEP325: Switch expressions spec > On Fri, Apr 20, 2018 at 11:55 AM, Guy Steele < [ mailto:[email protected] > | > [email protected] ] > wrote: >> You know, if s2 is short (say, less than 30 or 40 characters), there are >> worse >> things than writing >> case A -> s1; >> case null -> s2; >> default -> s2; >> especially if you use spaces (as I just did) to line up the two occurrences >> of >> s2 to make it easy to see they are identical. >> And if s2 is long, there are worse things than making a little sub method to >> handle it: >> case A -> s1; >> case null -> frobboz(a, b); >> default -> frobboz(a, b); >> int frobboz(int a, String b) { … } >> And if even THAT is not satisfactory, well, there are worse things than >> giving >> up on the arrows and just using colons (and break, if needed). > I think neither of these goes down well. Having to repeat yourself at all, > while > normal cases get to use comma, will feel very wrong. Having to abandon > arrowform over this would be even worse. >> BUT, on the other hand, if we wanted to: instead of, or in addition to, >> case pat1, pat2, pat3 -> s; >> we could allow the form >> case pat1 -> case pat2 -> case pat3 -> s; > This seems like a step backward to me (whether it is instead or in addition). > fwiw, I think `default, case null ->` is superior to all of these options. > -- > Kevin Bourrillion | Java Librarian | Google, Inc. | [ > mailto:[email protected] | > [email protected] ]
