JEP325: Switch expressions spec
Kevin Bourrillion
kevinb at google.com
Mon Apr 23 18:02:30 UTC 2018
On Fri, Apr 20, 2018 at 11:55 AM, Guy Steele <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. | kevinb at google.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openjdk.java.net/pipermail/amber-spec-experts/attachments/20180423/36ac1d0c/attachment.html>
More information about the amber-spec-experts
mailing list