> De: "Brian Goetz" <[email protected]>
> À: "Kevin Bourrillion" <[email protected]>
> Cc: "Remi Forax" <[email protected]>, "amber-spec-experts"
> <[email protected]>
> 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