instanceof with primitive type

Angelos Bimpoudis angelos.bimpoudis at oracle.com
Wed Nov 8 22:56:41 UTC 2023


Hello Ella,

Indeed. The bullet you showed is now deleted from both. The line you have put in bold, replaces the other two.

Thanks for bringing this up.
Aggelos
________________________________
From: amber-dev <amber-dev-retn at openjdk.org> on behalf of Ella Ananeva <ella.ananeva at oracle.com>
Sent: 08 November 2023 19:18
To: amber-dev at openjdk.org <amber-dev at openjdk.org>
Subject: instanceof with primitive type


Hi team,

Reading JEP 455 spec<https://cr.openjdk.org/~abimpoudis/instanceof/jep455-20231030/specs/instanceof-jls.html#jls-15.20.2>, I see this:

The type of the expression RelationalExpression can be a reference type, a primitive type or the null type.

And then, later:

The following rules apply when instanceof is the pattern match operator:

  *   The type of the expression RelationalExpression must be a reference type or the null type, or a compile-time error occurs.



But I would expect that primitive types in patterns should be good, too. And in the freshest version of JEP_455 JDK<https://mach5.us.oracle.com/mdash/buildIds/2023-11-06-1633093.angelos.bimpoudis.dev>, both examples compile and print “Yes”:



Integer x = 5;
if (x instanceof int y) System.out.println("Yes");



int x = 5;
if (x instanceof Integer y) System.out.println("Yes");



Shouldn’t the spec be updated?



Thank you,

Ella Ananeva
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/amber-dev/attachments/20231108/a63f4dae/attachment.htm>


More information about the amber-dev mailing list