New JEP: Switch Expressions for the Java Language
kevinb at google.com
Mon Dec 11 18:10:50 UTC 2017
On Sun, Dec 10, 2017 at 2:40 PM, Brian Goetz <brian.goetz at oracle.com> wrote:
So, speaking semantically only:
> - We should not allow fall through in expression switch; I don’t think it
> makes any sense.
> - I’m pretty convinced that nonlocal returns out of expression switch
> (other than throwing) is similarly a wrong fit. (We allow this in neither
> conditional expressions nor lambdas.)
> - Switch expressions should definitely be able to reference locals, but
> we’re open minded to some restrictions (such as no mutation).
> - We could justify allowing switch expressions to mutate locals, since
> other expressions can too, but we could similarly justify restricting
> - More strongly, we could justify restricting even referencing
> non-eff-final locals, though this is starting to get onto thin ice, because
> the only argument we have for this is “for (superficial) consistency with
> lambdas”, which is pretty weak.
I believe I agree on all points. I think replacing : with -> is a very nice
fit even if it's slightly more permissive than a lambda. Being just as
restrictive does not seem justified.
Kevin Bourrillion | Java Librarian | Google, Inc. | kevinb at google.com
More information about the amber-spec-observers