Updated patterns-in-switch doc

Brian Goetz brian.goetz at oracle.com
Sun Sep 13 13:53:18 UTC 2020

> if we don't have constant pattern, it may also means that the type of a bound variables can be implicit too.
> i.e. case Point(x, y) having the same meaning as case Point(var x, var y) like with lambdas.

I don’t quite get the leap from “no constant patterns” to changing the syntax of deconstruction patterns, but in any case, we definitely don’t want this (and in fact, for the same reasons cited in the section on constant patterns, and others.)  

I don’t want people wondering whether `foo(x)` is an invocation of a method or a pattern.  One of the problems with the obvious denotation of constant patterns is that `foo(0)` looks like an invocation with zero.  With a variable, it is worse.  

Further, allowing `Point(x,y)` as a pattern would allow variables to be declared without anything that even looks like a variable declaration!  Many people are already disturbed by the idea that variables can now be declared from within expressions; without an `int x` or `var x` to at least have a declaration to point to, it will be untenable.  

> is not valid anymore and should be written like this
>   int c = ...
>   switch(getFoo()) {
>     case Foo(x) where x == c: ...
>   }

No, it should be written

    case Foo(var x) where x == c: 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.java.net/pipermail/amber-spec-experts/attachments/20200913/0bd46463/attachment.htm>

More information about the amber-spec-experts mailing list