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

implementing Record Classes as a standard feature in Java

    XMLWordPrintable

    Details

    • Type: CSR
    • Status: Closed
    • Priority: P3
    • Resolution: Approved
    • Fix Version/s: 16
    • Component/s: core-libs
    • Labels:
    • Subcomponent:
    • Compatibility Risk:
      minimal
    • Compatibility Risk Description:
      No change in behavior. Provides unrestricted use of a new feature.
    • Interface Kind:
      Java API
    • Scope:
      SE

      Description

      Summary

      Record Classes were originally proposed by JEP 359 in early 2019. JEP 359 was targeted to JDK 14 as a preview feature. Feedback on the feature was positive but it was suggested that the feature should be previewed again, to gain more experience. Some changes were proposed including relaxing the requirement that canonical constructor must be public, along with support for local enum classes and interfaces (alongside local record classes). The feature was previewed a second time by JEP 384 which was targeted to JDK 15. Feedback on JDK 15 suggests that the Record Classes feature is now ready to be made final and permanent.

      Problem

      The preview status of Record Classes prevents usage in standard Java.

      Solution

      Remove the preview status requirement from Record Classes.

      Specification

      This CSR is concerned only with removing the preview status from the Java API. The changes are listed below.

      Java API

      diff --git a/src/java.base/share/classes/java/lang/Class.java b/src/java.base/share/classes/java/lang/Class.java
      index 1fabad43738..5c64ababc11 100644
      --- a/src/java.base/share/classes/java/lang/Class.java
      +++ b/src/java.base/share/classes/java/lang/Class.java
           /**
      -     * {@preview Associated with records, a preview feature of the Java language.
      -     *
      -     *           This method 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.}
      -     *
            * Returns an array of {@code RecordComponent} objects representing all the
            * record components of this record class, or {@code null} if this class is
            * not a record class.
      @@ -2385,11 +2378,8 @@ public Method getMethod(String name, Class<?>... parameterTypes)
            *          </ul>
            *
            * @jls 8.10 Record Types
      -     * @since 14
      +     * @since 16
            */
      -    @jdk.internal.PreviewFeature(feature=jdk.internal.PreviewFeature.Feature.RECORDS,
      -                                 essentialAPI=false)
      -    @SuppressWarnings("preview")
           @CallerSensitive
           public RecordComponent[] getRecordComponents() {
               SecurityManager sm = System.getSecurityManager();
      @@ -3688,13 +3678,6 @@ public boolean isEnum() {
           }
      
           /**
      -     * {@preview Associated with records, a preview feature of the Java language.
      -     *
      -     *           This method 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.}
      -     *
            * Returns {@code true} if and only if this class is a record class.
            *
            * <p> The {@linkplain #getSuperclass() direct superclass} of a record
      @@ -3707,10 +3690,8 @@ public boolean isEnum() {
            *
            * @return true if and only if this class is a record class, otherwise false
            * @jls 8.10 Record Types
      -     * @since 14
      +     * @since 16
            */
      -    @jdk.internal.PreviewFeature(feature=jdk.internal.PreviewFeature.Feature.RECORDS,
      -                                 essentialAPI=false)
           public boolean isRecord() {
               return getSuperclass() == JAVA_LANG_RECORD_CLASS && isRecord0();
           }
      diff --git a/src/java.base/share/classes/java/lang/Record.java b/src/java.base/share/classes/java/lang/Record.java
      index 4d568e8baa0..121fc7ce73c 100644
      --- a/src/java.base/share/classes/java/lang/Record.java
      +++ b/src/java.base/share/classes/java/lang/Record.java
      @@ -25,14 +25,6 @@
       package java.lang;
      
       /**
      - * {@preview Associated with records, a preview feature of the Java language.
      - *
      - *           This class is associated with <i>records</i>, a preview
      - *           feature of the Java language. Programs can only use this
      - *           class when preview features are enabled. Preview features
      - *           may be removed in a future release, or upgraded to permanent
      - *           features of the Java language.}
      - *
        * This is the common base class of all Java language record classes.
        *
        * <p>More information about records, including descriptions of the
      @@ -86,10 +78,8 @@
        * <a href="{@docRoot}/java.base/java/io/ObjectInputStream.html#record-serialization">record serialization</a>.
        *
        * @jls 8.10 Record Types
      - * @since 14
      + * @since 16
        */
      -@jdk.internal.PreviewFeature(feature=jdk.internal.PreviewFeature.Feature.RECORDS,
      -                             essentialAPI=true)
       public abstract class Record {
           /**
            * Constructor for record classes to call.
      diff --git a/src/java.base/share/classes/java/lang/annotation/ElementType.java b/src/java.base/share/classes/java/lang/annotation/ElementType.java
      index 15182f2a87b..db4e65a2b45 100644
      --- a/src/java.base/share/classes/java/lang/annotation/ElementType.java
      +++ b/src/java.base/share/classes/java/lang/annotation/ElementType.java
      @@ -118,22 +118,12 @@
           MODULE,
      
           /**
      -     * {@preview Associated with records, a preview feature of the Java language.
      -     *
      -     *           This constant is associated with <i>records</i>, a preview
      -     *           feature of the Java language. Programs can only use this
      -     *           constant when preview features are enabled. Preview features
      -     *           may be removed in a future release, or upgraded to permanent
      -     *           features of the Java language.}
      -     *
            * Record component
            *
            * @jls 8.10.3 Record Members
            * @jls 9.7.4 Where Annotations May Appear
            *
      -     * @since 14
      +     * @since 16
            */
      -    @jdk.internal.PreviewFeature(feature=jdk.internal.PreviewFeature.Feature.RECORDS,
      -                                 essentialAPI=true)
           RECORD_COMPONENT;
       }
      diff --git a/src/java.base/share/classes/java/lang/reflect/RecordComponent.java b/src/java.base/share/classes/java/lang/reflect/RecordComponent.java
      index 225a0999f17..7079f3d28f7 100644
      --- a/src/java.base/share/classes/java/lang/reflect/RecordComponent.java
      +++ b/src/java.base/share/classes/java/lang/reflect/RecordComponent.java
      @@ -38,23 +38,14 @@
       import java.util.Objects;
      
       /**
      - * {@preview Associated with records, a preview feature of the Java language.
      - *
      - *           This class 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.}
      - *
        * A {@code RecordComponent} provides information about, and dynamic access to, a
        * component of a record class.
        *
        * @see Class#getRecordComponents()
        * @see java.lang.Record
        * @jls 8.10 Record Types
      - * @since 14
      + * @since 16
        */
      -@jdk.internal.PreviewFeature(feature=jdk.internal.PreviewFeature.Feature.RECORDS,
      -                             essentialAPI=false)
       public final class RecordComponent implements AnnotatedElement {
           // declaring class
           private Class<?> clazz;
      diff --git a/src/java.base/share/classes/java/lang/runtime/ObjectMethods.java b/src/java.base/share/classes/java/lang/runtime/ObjectMethods.java
      index f1115b6c36d..ad50a002f71 100644
      --- a/src/java.base/share/classes/java/lang/runtime/ObjectMethods.java
      +++ b/src/java.base/share/classes/java/lang/runtime/ObjectMethods.java
      @@ -38,23 +38,14 @@
       import java.util.Objects;
      
       /**
      - * {@preview Associated with records, a preview feature of the Java language.
      - *
      - *           This class 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.}
      - *
        * Bootstrap methods for state-driven implementations of core methods,
        * including {@link Object#equals(Object)}, {@link Object#hashCode()}, and
        * {@link Object#toString()}.  These methods may be used, for example, by
        * Java compiler implementations to implement the bodies of {@link Object}
        * methods for record classes.
        *
      - * @since 14
      + * @since 16
        */
      -@jdk.internal.PreviewFeature(feature=jdk.internal.PreviewFeature.Feature.RECORDS,
      -                             essentialAPI=false)
       public class ObjectMethods {
      
           private ObjectMethods() { }
      diff --git a/src/java.base/share/classes/sun/reflect/annotation/TypeAnnotation.java b/src/java.base/share/classes/sun/reflect/annotation/TypeAnnotation.java
      index 6fc8ad93384..bcd0761dfa6 100644
      --- a/src/java.base/share/classes/sun/reflect/annotation/TypeAnnotation.java
      +++ b/src/java.base/share/classes/sun/reflect/annotation/TypeAnnotation.java
      @@ -92,16 +92,8 @@ public LocationInfo getLocationInfo() {
               METHOD_FORMAL_PARAMETER,
               THROWS,
               /**
      -         * {@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.}
      -         * @since 14
      +         * @since 16
                */
      -        @jdk.internal.PreviewFeature(feature=jdk.internal.PreviewFeature.Feature.RECORDS,
      -                                     essentialAPI=false)
               RECORD_COMPONENT;
           }

        Attachments

        1. recordsVM.diff
          1 kB
        2. records.diff
          12 kB
        3. Record Classes-2.pdf
          654 kB
        4. record_classes_specs_10_06_2020.zip
          229 kB
        5. record_classes_specs_09_28_2020.zip
          163 kB
        6. jep395-20201204.zip
          225 kB
        7. jep395-20201103.zip
          231 kB

          Issue Links

            Activity

              People

              Assignee:
              vromero Vicente Arturo Romero Zaldivar
              Reporter:
              gbierman Gavin Bierman
              Reviewed By:
              Gavin Bierman
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: