[External] : Re: Primitive type patterns

Brian Goetz brian.goetz at oracle.com
Thu Apr 7 21:24:05 UTC 2022

> We already discussed those rules when we discuss instanceof,  it means 
> that "x instanceof primitive" has different meaning depending on the 
> type of x

No, it does not.  It means "does x match the pattern P" everywhere. It 
is pattern P is that has different meanings depending on type. This may 
sound like a silly distinction, but it is not!  Pattern matching is 
inherently polymorphic -- it is all about reflecting dynamic conversions 
statically -- and exhibits the *same* polymorphism regardless of where 
it occurs.

>   Object x = ...
>   if (x instanceof short) { ... }   // <=> instanceof Short + unboxing

Where x is a reference type, yes.  How is that not a reasonable question 
to ask?   And, why would we not want duality with:

     record R(short s) { }
     new R(x)

Asking `r instanceof R(short s)` is akin to asking "could this R have 
come from passing some x to the R constructor".   And that would work if 
x were byte, or x were a long literal in the value range of short, or a 
Short, or....

> It's also another creative way to have an action at distance,

More like *the same* way.

Anyway, your opposition to the entirety of this sub-feature is noted.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.java.net/pipermail/amber-spec-experts/attachments/20220407/b6e7972c/attachment.htm>

More information about the amber-spec-experts mailing list