<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Windows-1252">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
.MsoChpDefault
        {mso-style-type:export-only;}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
        {page:WordSection1;}
--></style>
</head>
<body lang="NL-BE" link="blue" vlink="#954F72" style="word-wrap:break-word">
<div class="WordSection1">
<p class="MsoNormal"><span lang="EN-GB">Hi all<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">I've long considered whether I should voice my opinion on
<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">the matter or not, given that I felt like some of my
<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">arguments had already been made before. <o:p>
</o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">Spoiler, I'm not a fan of `instanceof byte`.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">Every time I write this email, I recheck something in
<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">the archives to check something and realize that someone<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">already said *something* about one of the arguments I'm<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">trying to make. So here is just a list of things that<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">have come up that I still felt like mentioning something.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">---<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">I asked a whether the following would be legal in an earlier email.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">The draft now explains that it is, but I still wonder what this snippet<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">would get desugared to.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">```java<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">Number num = ...;<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">if (num instanceof byte b) {<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">    ...<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">}<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">```<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">---<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">On 2023-01-27 at 12:01 UTC, Ron Pressler wrote
<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">(as reaction to an email by Remi Forax on 2023-01-27 at 11:06 UTC):<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">> §4.10.1 of the JLS has stated that a subtyping relationship among primitives exists (byte <: short <: int <: long, float <: double) since at least Java 1.6 (possibly earlier).<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">>> By example, you can not override a method that returns a double with a method that returns an int because overriding is about subtyping relationship, not conversion (for the history, Neal Gafter had implemented method
 overriding that allow primitive conversions in javac in one of the early versions of Java 1.5 but to it was decided to not go that path).<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">> The rules for return types in overridden methods (§8.4.8.3) doesn’t refer to subtyping but to "return-type-substitutability” (§8.4.5) which, in turn, also doesn’t talk about subtyping but only about subtyping *in the
 case that the return type is a reference type*. So even though there is a subtyping relationship between int and long (though not between int and double), they are not return-type-substitutable, which places additional constraints beyond mere subtyping.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">It seems you missed a single line in the spec. `long` is also a
<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">direct subtype of `float` so `int` is in fact a subtype of `double`<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">>> I agree that revisiting concepts is something we have to do, but breaking the difference between subtyping and primitive conversions for a corner case, in isolation, is a decision hard to understand.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">> First, a subtyping relationship for primitives does exist, though it doesn’t cover all of the possible conversions.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">Second, nothing is broken, shattered, or wrecked even in cases subtyping doesn’t exist, because the draft doesn’t propose to *change* the meaning of patterns, but rather to generalise them. I.e. its insight is that subtyping
 is a special case of assignment conversion, and so patterns are “really” about the validity of such conversions rather than about the specific case of subtyping.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">I had a quick look over the spec and I couldn't find any place that<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">actually used the subtyping relation between primitives. The case
<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">you seem to be claiming widening primitive conversion matches 100%<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">with the rules about subtyping, it actually doesn't use subtyping
<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">at all and just lists all possible conversions.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">A interesting question that could be asked is:<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">"What does subtype/supertype mean". Although it is used in the spec<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">it isn't really explain apart from being a reflexive and transitive<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">relationship between types.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">---<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">A few of the emails argue that we should see `instanceof` as a<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">safe cast check, not like an "inheritance" check or<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">a "reference subtype" check. If the operator was called
<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">`canbesafelyconvertedto` I might agree, but thats not the case.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">It feels very weird (to me) to not have an operator called
<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">`instanceof`, not check whether the lhs is an instance of the
<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">rhs. <o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">Some of you might be thinking: "I guess you want to argue that<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">you can't have instances of an `byte` so `instanceof byte`<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">doesn't make sense", which isn't true. Valhalla discussions
<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">have agreed that `byte` has instances. It has 256 different ones:<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">the values from -128 to 127.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">Now this might seem I'm arguing in favour of `instanceof byte`.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">And on it's own that might look correct, but then you have<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">justify the fact that the integer values/instances between -128<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">and 127 and the byte values/instances are the same. In my mind<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">the way this would be justified is by using the fact that `byte`<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">is a subtype of `int` which is why it's set of instances is a
<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">subset of the instances of `int`. But this raises the issue<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">that the set of instances of `int` can't be a subset of the set<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">of instances of `float` cause not all ints are valid floats.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">---<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">I feel like I spend too much time writing, rewriting and deleting this<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">email so this is it (for now).<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">TL; DR: I don't like `instanceof byte` and JLS chapter 4.10.1<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">Kind regards<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">Robbe Pincket</span><span lang="EN-GB"><o:p></o:p></span></p>
</div>
</body>
</html>