Support for primitive types in instanceof and type patterns

Tagir Valeev amaembo at gmail.com
Wed Nov 16 16:50:55 UTC 2022


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
<angelos.bimpoudis at oracle.com> wrote:
>
> 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:
>
> https://bugs.openjdk.org/browse/JDK-8288476
>
> Suggestions are welcomed!
> Angelos


More information about the amber-spec-experts mailing list