New JEP: Switch Expressions for the Java Language
forax at univ-mlv.fr
forax at univ-mlv.fr
Wed Dec 13 10:08:04 UTC 2017
> De: "Brian Goetz" <brian.goetz at oracle.com>
> À: "Kevin Bourrillion" <kevinb at google.com>
> Cc: "Remi Forax" <forax at univ-mlv.fr>, "amber-spec-experts"
> <amber-spec-experts at openjdk.java.net>
> Envoyé: Lundi 11 Décembre 2017 20:28:17
> Objet: Re: New JEP: Switch Expressions for the Java Language
[...]
>> * Allowing `throw` as the RHS of a case makes sense, but let's carefully think
>> through the ramifications of making it an expression in general. Do we really
>> want to see code like this? void foo(Bar bar) { bar.isValid() || throw new
>> IllegalArgumentException(); }
> OK, let's pull on that string. The next logical place for it is conditional
> expressions:
> String s = (x >= 0) ? Integer.toString(x) : throw new IAE();
> This seems pretty reasonable too, though the if-else version is not horribly
> broken either. What about conditionals in method invocation context:
> m(x > 0 ? Integer.toString(x) : throw new IAE())
> I know I've wanted to be able to do this at times, though again, I've worked
> around it and lived, and surely it could be abused.
> I'm OK cutting this one back.
I think we should only allow throw as an expression if the precedent symbol was '->', i.e. only allows throw as an expression in lambda body and in the body of an expression switch.
It seems to cover what we want without making the code too un-java-y.
Rémi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openjdk.java.net/pipermail/amber-spec-experts/attachments/20171213/eb0354cd/attachment.html>
More information about the amber-spec-experts
mailing list