Named record pattern
Brian Goetz
brian.goetz at oracle.com
Tue May 31 14:49:02 UTC 2022
> Erm... I actually thought that it was your idea to allow the 'final'
> modifier on patterns. This change was introduced in Java 16 (when
> patterns for instanceof were finalized). Here's the initial e-mail
> from you (item 2):
> https://mail.openjdk.java.net/pipermail/amber-spec-experts/2020-August/002433.html
That mail is exactly the discussion point I was thinking of. But I
never said that there should be a way to declare them as final at all!
I said it was a mistake to have made them automatically final, and that
patterns should introduce ordinary mutable locals. I wasn't suggesting
an option, just that we'd picked the wrong default (and created a new
category of complexity in the process.)
But, its an honest leap from there to "well of course me must have meant
you could declare them final." But had this been explicitly raised, I
would have not been in favor of this option, for two reasons:
- The conversation we are having now -- it was clear that eventually,
some more complex pattern would introduce variables in a way such that
there was not an obvious "local variable" declaration, and that we would
eventually be having a "for consistency" discussion;
- The value of being able to declare these things final is almost
zero; the only reason we are having this conversation at all is "for
consistency" with local variables. But if someone said "should we add a
feature to let you make pattern variables final", the "meh" would have
been deafening.
>>> instanceof @Cartesian Point p'. It looks like I cannot do the same in
>>> the second case, which is another asymmetry.
>> We definitely intended to not allow declaration annotations.
> But they are allowed for type test patterns, since Java 16.
Yeah, we've got a problem.
More information about the amber-spec-experts
mailing list