JEP325: Switch expressions spec
Remi Forax
forax at univ-mlv.fr
Mon Apr 23 18:29:28 UTC 2018
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" <kevinb at google.com>
> À: "Guy Steele" <guy.steele at oracle.com>
> Cc: "amber-spec-experts" <amber-spec-experts at openjdk.java.net>
> 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:guy.steele at oracle.com |
> guy.steele at oracle.com ] > 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:kevinb at google.com |
> kevinb at google.com ]
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openjdk.java.net/pipermail/amber-spec-experts/attachments/20180423/bd8e9686/attachment.html>
More information about the amber-spec-experts
mailing list