Primitives in instanceof and patterns

Brian Goetz brian.goetz at oracle.com
Sat Sep 10 14:01:23 UTC 2022


> I think you are overstating how useful a pattern that do a range check is.

I think you're falling into the trap of examining each conversion and 
asking "would I want a pattern to do this."  That's a recipe for more 
complexity because we'll end up with another ad-hoc, 
not-like-anything-else construct (which is what the Java 19 primitive 
type pattern semantics is.)  It's not about "is range check useful" 
(though, it is), its about "is casting to/from primitives safely" useful.

> I'm not against changing what a type pattern is but it should be done 
> in concert with changing the other rules (overriding rules especially) 
> and the retrofitting of primitive types to value classes.

It's not about "changing other rules", its about aligning to them. We're 
aligning to cast conversion here.  When we have named patterns, we will 
have to define overload selection for patterns; again, this should just 
be the existing overload selection with "arrows reversed", which means 
we want boxing for patterns to also be "boxing with arrows reversed" 
(otherwise it doesn't compose.) The language we have now is telling us 
how patterns should work; we should listen.



More information about the amber-spec-observers mailing list