Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8251554 JEP 401: Value Classes and Objects (Preview)
  3. JDK-8317277

Java language implementation of value classes and objects

    XMLWordPrintable

Details

    • Sub-task
    • Resolution: Unresolved
    • P4
    • None
    • None
    • tools
    • None

    Description

      This task summarizes the language changes introduced by JEP 401. All features are activated by the `--enable-preview` javac option.



      ### 'value' classes and interfaces

      A class with the 'value' modifier, either concrete or abstract, is subject to the following rules:

      - All instance fields are implicitly 'final'
      - All fields must be initialized before the 'super' call (see also construction, below)
      - No instance methods may be 'synchronized'
      - (Possibly) The class does not declare a 'finalize' method
      - Extends an abstract value class or 'Object'
      - If not 'abstract', is implicitly 'final'

      Abstract value classes may declare (final) instance fields.

      A record class may be declared a 'value record' and is subject to these rules.



      ### Value class construction

      As enabled by JEP 447, any blank fields of a class may be assigned to before the 'super()' call.

      In value classes, there are two changes in the timing of implicit constructor code:

      - Instance field initializers are executed immediately upon entry to a non-'this()'-calling constructor. (Alternatively, instance field initializers could be prohibited entirely.)

      - An implicit 'super()' call occurs at the *end* of a constructor that lacks an explicit constructor call.

      Instance initializer blocks continue to run immediately after a 'super' call, wherever it occurs.

      These changes imply that, in value classes, instance field initializers and "simple" constructor bodies occur in a pre-construction context and are not allowed to refer to 'this'.


      ### Compilation

      See JDK-8317278 for class file format.

      All classes are generated with the preview version number.

      The ACC_IDENTITY and ACC_STRICT modifiers are set according to the language rules.

      In each compiled class file, any concrete value class that appears in the descriptor of any declared or referenced field or method is named by the class file's `Preload` attribute.



      ### Class file reading

      When preview features are enabled, the following classes are considered to be value classes when loaded from class files:
      - java.lang.Number
      - java.lang.Record
      - All 8 primitive wrapper classes
      - java.util.Optional



      ### Other language tools and APIs

      - 'javadoc' output indicates when a class is a value class.

      - 'javax.lang.model' is updated to support the 'value' modifier.

      - 'java.lang.invoke.LambdaMetafactory' may experiment with value classes as lambda classes.

      Attachments

        Issue Links

          Activity

            People

              vromero Vicente Arturo Romero Zaldivar
              dlsmith Dan Smith
              Votes:
              1 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated: