<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<font size="4"><font face="monospace">I agree and disagree. <br>
<br>
I agree that range checking of other ranges is useful and
something that belongs on the "candidate features" list. In
fact, it's been on my list for a while. <br>
<br>
But I disagree that this is the time or place for it, or the
best way to do it. Range checking may be one way to view
"instanceof byte", but a more general way is that is the
precondition for safely casting to byte. And the language
defines casting rules not only from other integral types, but
from floating point types as well. <br>
<br>
That said, we've been keeping our eye on ranges in general,
since they are useful in lots of places besides patterns, such
as: <br>
<br>
// loops<br>
for (int i : 1..10) // we can argue over inclusive vs
exclusive<br>
for (int i : array.range()) // range returns a
Range<int>, which is Iterable<int><br>
<br>
// case labels<br>
case 1..10: ...<br>
<br>
We could do this today, but we could do better tomorrow with
features coming from Valhalla. This is how I'm thinking we'll
get there. <br>
<br>
<br>
</font></font><br>
<div class="moz-cite-prefix">On 11/16/2022 11:50 AM, Tagir Valeev
wrote:<br>
</div>
<blockquote type="cite" cite="mid:CAE+3fjasXNOKon=608DQvwTkm5C5A2M11imo=SchU731kqbCqw@mail.gmail.com">
<pre class="moz-quote-pre" wrap="">Hello!
>From what I see, `instanceof byte`, `instanceof short`, `instanceof
char` and `instanceof int` applied to a wider integral value are four
range-checking conditions. In many cases, people may want to check
against different (but compile-time constant) range. It looks too
restrictive to support only four specific ranges. I understand the
rationale about symmetry between primitive and reference types but the
usefulness looks very limited to me. Supporting custom ranges, like
`instanceof int(>0) x` or `instanceof byte(0..100) b` or something
like this (with dominance and exhaustiveness checks in switch) would
be much more useful. I agree that this would also require much more
work, but at least it would be nice to take this in mind as a possible
future improvement.
With best regards,
Tagir Valeev.
On Tue, Nov 15, 2022 at 12:20 AM Angelos Bimpoudis
<a class="moz-txt-link-rfc2396E" href="mailto:angelos.bimpoudis@oracle.com"><angelos.bimpoudis@oracle.com></a> wrote:
</pre>
<blockquote type="cite">
<pre class="moz-quote-pre" wrap="">
Dear experts,
The draft JEP for adding support for primitive types in instanceof and type patterns, that has been previously discussed on this list, is available at:
<a class="moz-txt-link-freetext" href="https://bugs.openjdk.org/browse/JDK-8288476">https://bugs.openjdk.org/browse/JDK-8288476</a>
Suggestions are welcomed!
Angelos
</pre>
</blockquote>
</blockquote>
<br>
</body>
</html>