<div dir="ltr"><div>Not that I've been able to digest this *entire* discussion, but in some ways this is the crux of it for me:</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Jan 26, 2023 at 6:40 PM Brian Goetz <<a href="mailto:brian.goetz@oracle.com">brian.goetz@oracle.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><br>In reality, `instanceof` is closely related to _casting_. In <br>
pre-patterns code, nearly 100% of instanceof checks are followed by a <br>
cast to the same type (why else would you ask instanceof?), and almost <br>
as many casts are preceded by an instanceof for that same type (and many <br>
that don't are bugs). This is not an accident. Instanceof is how we ask <br>
whether it would it be safe to cast to a given type, before doing <br>
something that might fail.</blockquote><div><br></div><div>(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.)</div><div><br></div><div>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".</div><div><br></div><div>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.</div><div><br></div><div>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.</div><div><br></div></div>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div style="line-height:1.5em;padding-top:10px;margin-top:10px;color:rgb(85,85,85);font-family:sans-serif"><span style="border-width:2px 0px 0px;border-style:solid;border-color:rgb(213,15,37);padding-top:2px;margin-top:2px">Kevin Bourrillion |</span><span style="border-width:2px 0px 0px;border-style:solid;border-color:rgb(51,105,232);padding-top:2px;margin-top:2px"> Java Librarian |</span><span style="border-width:2px 0px 0px;border-style:solid;border-color:rgb(0,153,57);padding-top:2px;margin-top:2px"> Google, Inc. |</span><span style="border-width:2px 0px 0px;border-style:solid;border-color:rgb(238,178,17);padding-top:2px;margin-top:2px"> <a href="mailto:kevinb@google.com" target="_blank">kevinb@google.com</a></span></div></div></div></div></div></div></div></div>