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

Compiler implementation for records

XMLWordPrintable

    • Icon: CSR CSR
    • Resolution: Approved
    • Icon: P3 P3
    • 14
    • tools
    • None
    • minimal
    • Hide
      The addition of the feature does not by itself bring a compatibility risk.

      Records are a preview feature in Java SE 14. It is possible that incompatible changes will be made to records in a later Java SE release, before they become final and permanent, but chances are low as records are ultimately Java classes so they shouldn't be introducing any new disruptive feature that could pose a compatibility risk. It is also possible that records will be removed in a later Java SE release, without ever having become final and permanent.
      Show
      The addition of the feature does not by itself bring a compatibility risk. Records are a preview feature in Java SE 14. It is possible that incompatible changes will be made to records in a later Java SE release, before they become final and permanent, but chances are low as records are ultimately Java classes so they shouldn't be introducing any new disruptive feature that could pose a compatibility risk. It is also possible that records will be removed in a later Java SE release, without ever having become final and permanent.
    • Language construct
    • SE

      Summary

      Add record classes to the Java language. Record classes, a.k.a. records, allow the definition of shallowly immutable, transparent carriers for a fixed set of values, the record components.

      Problem

      Modeling data classes with the Java language is possible but users have to generate a lot of boilerplate to model even the simplest of them. There is also a lot of repetition implying a lot of places for bugs to hide. Users are forced to provide implementations for methods like: toString, equals and hashCode even when those implementations could be directly derived from the state of transparent data carriers and easy to generate automatically by a compiler.

      Solution

      The Java language will be enhanced by supporting record classes: a new construction for the definition of shallowly immutable, transparent carriers for a fixed set of values, its record components. These feature will constitute a preview feature (JEP 12) in Java SE 14.

      Specification

      diff -r fd51f02ef75c -r cba5b68a6424 src/jdk.compiler/share/classes/com/sun/source/tree/ClassTree.java
      --- a/src/jdk.compiler/share/classes/com/sun/source/tree/ClassTree.java Mon Nov 18 16:30:21 2019 -0500
      +++ b/src/jdk.compiler/share/classes/com/sun/source/tree/ClassTree.java Mon Nov 18 16:40:42 2019 -0500
      @@ -29,7 +29,7 @@
       import javax.lang.model.element.Name;
      
       /**
      - * A tree node for a class, interface, enum, or annotation
      + * A tree node for a class, interface, enum, record, or annotation
        * type declaration.
        *
        * For example:
      @@ -44,6 +44,7 @@
        *
        * @jls 8.1 Class Declarations
        * @jls 8.9 Enum Types
      + * @jls 8.10 Record Types
        * @jls 9.1 Interface Declarations
        * @jls 9.6 Annotation Types
        *
      diff -r fd51f02ef75c -r cba5b68a6424 src/jdk.compiler/share/classes/com/sun/source/tree/Tree.java
      --- a/src/jdk.compiler/share/classes/com/sun/source/tree/Tree.java      Mon Nov 18 16:30:21 2019 -0500
      +++ b/src/jdk.compiler/share/classes/com/sun/source/tree/Tree.java      Mon Nov 18 16:40:42 2019 -0500
      @@ -644,6 +644,20 @@
               PROVIDES(ProvidesTree.class),
      
               /**
      +         * {@preview Associated with records, a preview feature of the Java language.
      +         *
      +         *           This enum constant is associated with <i>records</i>, a preview
      +         *           feature of the Java language. Preview features
      +         *           may be removed in a future release, or upgraded to permanent
      +         *           features of the Java language.}
      +         *
      +         * Used for instances of {@link ClassTree} representing records.
      +         *
      +         * @since 14
      +         */
      +        RECORD(ClassTree.class),
      +
      +        /**
                * Used for instances of {@link RequiresTree} representing
                * requires directives in a module declaration.
                */

      In addition, proposed changes to the JLS are available at http://cr.openjdk.java.net/~gbierman/jep359/jep359-20191125/specs/records-jls.html

            vromero Vicente Arturo Romero Zaldivar
            vromero Vicente Arturo Romero Zaldivar
            Alex Buckley, Jan Lahoda
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved: