Draft JEP on Primitive types in patterns, instanceof, and switch

Kevin Bourrillion kevinb at google.com
Fri Jan 27 19:06:36 UTC 2023


Not that I've been able to digest this *entire* discussion, but in some
ways this is the crux of it for me:

On Thu, Jan 26, 2023 at 6:40 PM Brian Goetz <brian.goetz at oracle.com> wrote:

>
> In reality, `instanceof` is closely related to _casting_.  In
> pre-patterns code, nearly 100% of instanceof checks are followed by a
> cast to the same type (why else would you ask instanceof?), and almost
> as many casts are preceded by an instanceof for that same type (and many
> that don't are bugs).  This is not an accident. Instanceof is how we ask
> whether it would it be safe to cast to a given type, before doing
> something that might fail.


(First, this claim is something I could gather some data on if it was truly
needed, but I don't think it is and I'd put very long odds on it being
wrong.)

I think the mental models we gravitate to, and that serve us best, are the
functional ones: the ones that most tangibly correlate choices we might
make to outcomes we might get. Talking of gravity, if I'm standing at the
edge of a rooftop, my mental model of gravity is not particles
attracting each other by the inverse square, it's "if I take a step, I will
at best be in a lot of pain".

I think this is one of those cases. *Any* deeper notion of what
`instanceof` "really IS" just aren't going to be relevant to programmers.

I wanted to add my few lines of support here. But I think, Stephen, that
the discussion sparked from your post can probably do no more good here, as
you essentially stated up front in your first four words.

-- 
Kevin Bourrillion | Java Librarian | Google, Inc. | kevinb at google.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/amber-dev/attachments/20230127/3165b1b4/attachment.htm>


More information about the amber-dev mailing list