Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8338013

[lworld] User defined value classes cannot extend j.l.Number

XMLWordPrintable

      In JEP 401, Number should be migrated to an abstract value class together with Record. However, user-defined value class like in this attached One.java, which is the most simple implementation implementing 4 abstract methods, cannot extend Number, with the error message like:

      $ $valhalla/bin/javac --enable-preview --release 23 One.java
      One.java:1: error: The identity type Number cannot be a supertype of the value type One
      value class One extends Number {
            ^
      Note: One.java uses preview features of Java SE 23.
      Note: Recompile with -Xlint:preview for details.

      This error does not happen with user-defined final value classes extending user-defined abstract value classes, or user-defined value records.

      This is originally showcased by Ethan McCue attending JVMLS 2024, first reproduced with the source code launcher.

      Note: Number has been migrated to an abstract value class, there was a bug and the compiler was setting both the value and the identity flag to migrated value classes. This was the reason of the issue

            vromero Vicente Arturo Romero Zaldivar
            liach Chen Liang
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: