<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=utf-8">
<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;}
@font-face
{font-family:"Segoe UI";
panose-1:2 11 5 2 4 2 4 2 2 3;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0cm;
font-size:11.0pt;
font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
code
{mso-style-priority:99;
font-family:"Courier New";}
.MsoChpDefault
{mso-style-type:export-only;}
@page WordSection1
{size:612.0pt 792.0pt;
margin:70.85pt 70.85pt 70.85pt 70.85pt;}
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<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 did a quick look over this new jep and had some questions.<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">1. I was wondering if the following is legal:<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">and if yes, is it equivalent to:<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">if (num instanceof Byte $b) {<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB"> byte b = $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">or:<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">if (<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB"> num instanceof Long $l && $l.longValue() instanceof byte b ||<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB"> num instanceof Integer $i && $i.intValue() instanceof byte b ||<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB"> num instanceof Short $s && $s.shortValue() instanceof byte b ||<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB"> num instanceof Byte $b && $b.byteValue() instanceof byte b ||<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB"> num instanceof Character $c && $c.charValue() instanceof byte b ||<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB"> num instanceof Float $f && $f.floatValue() instanceof byte b ||<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB"> num instanceof Double $d && $d.doubleValue() 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">To me it feels like it should be the second to match with the rest of the idea of primitive matching, but that means a rather small expression hides a lot of complexity<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">2. How will this interact with valhalla<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">Currently, if I have a `record Box<T>(T item) {}`, then item is always a reference type. However, as I understand the current plans of valhalla, this won't always be true in the future, and item could be an `int` or a
`byte`. How would `intanceof Box(byte x)` end up getting compiled? I suppose that is also a question about how pattern matching interacts with universal/specialized generics in the first place, but it seems to me that this jep could influence that so it should
probably be taken into consideration.<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<o:p></o:p></span></p>
<p class="MsoNormal"><o:p> </o:p></p>
<div style="mso-element:para-border-div;border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0cm 0cm 0cm">
<p class="MsoNormal" style="border:none;padding:0cm"><b>From: </b><a href="mailto:angelos.bimpoudis@oracle.com">Angelos Bimpoudis</a><br>
<b>Sent: </b>dinsdag 15 november 2022 0:21<br>
<b>To: </b><a href="mailto:amber-spec-experts@openjdk.java.net">amber-spec-experts</a><br>
<b>Subject: </b>Support for primitive types in instanceof and type patterns</p>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<p class="MsoNormal" style="background:white"><span style="font-family:"Segoe UI",sans-serif;color:black">Dear experts,
<o:p></o:p></span></p>
</div>
<div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-family:"Segoe UI",sans-serif;color:black"><o:p> </o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-family:"Segoe UI",sans-serif;color:black">The draft JEP for adding support for primitive types in
</span><code><span style="font-size:10.0pt;color:black">instanceof</span></code><span style="font-family:"Segoe UI",sans-serif;color:black"> and type patterns, that has been previously discussed on this list, is available at:<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-family:"Segoe UI",sans-serif;color:black"><o:p> </o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-family:"Segoe UI",sans-serif;color:black">https://bugs.openjdk.org/browse/JDK-8288476<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-family:"Segoe UI",sans-serif;color:black"><o:p> </o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-family:"Segoe UI",sans-serif;color:black">Suggestions are welcomed!<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal" style="background:white"><span style="font-family:"Segoe UI",sans-serif;color:black">Angelos<o:p></o:p></span></p>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
</body>
</html>