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

j.l.Record need to mention that canonical constructor may not be public

XMLWordPrintable

    • Icon: CSR CSR
    • Resolution: Approved
    • Icon: P3 P3
    • 15
    • core-libs
    • None
    • behavioral
    • minimal
    • Java API
    • SE

      Summary

      Specification for java.lang.Record is not in sync with the records spec and should be updated

      Problem

      The specification for java.lang.Record states that the canonical constructor must be public

      Solution

      Update the specification for java.lang.Record stating that the canonical constructor must provide at least as much access as the corresponding record class

      Specification

      diff -r 0a32396f7a69 src/java.base/share/classes/java/lang/Record.java
      --- a/src/java.base/share/classes/java/lang/Record.java Wed Jun 03 12:09:04 2020 -0400
      +++ b/src/java.base/share/classes/java/lang/Record.java Thu Jun 04 17:24:40 2020 -0400
      @@ -46,20 +46,21 @@
        * record components are declared in the record header.  The list of record
        * components declared in the record header form the <em>record descriptor</em>.
        *
      - * <p>A record class has the following mandated members: a public <em>canonical
      - * constructor</em>, whose descriptor is the same as the record descriptor;
      + * <p>A record class has the following mandated members: a <em>canonical
      + * constructor</em>, which must provide at least as much access as the record
      + * class and whose descriptor is the same as the record descriptor;
        * a private final field corresponding to each component, whose name and
        * type are the same as that of the component; a public accessor method
        * corresponding to each component, whose name and return type are the same as
        * that of the component.  If not explicitly declared in the body of the record,
        * implicit implementations for these members are provided.
        *
      - * <p>The implicit declaration of the canonical constructor initializes the
      - * component fields from the corresponding constructor arguments.  The implicit
      - * declaration of the accessor methods returns the value of the corresponding
      - * component field.  The implicit declaration of the {@link Object#equals(Object)},
      - * {@link Object#hashCode()}, and {@link Object#toString()} methods are derived
      - * from all of the component fields.
      + * <p>The implicit declaration of the canonical constructor has the same accessibility
      + * as the record class and initializes the component fields from the corresponding
      + * constructor arguments.  The implicit declaration of the accessor methods returns
      + * the value of the corresponding component field.  The implicit declaration of the
      + * {@link Object#equals(Object)}, {@link Object#hashCode()}, and {@link Object#toString()}
      + * methods are derived from all of the component fields.
        *
        * <p>The primary reasons to provide an explicit declaration for the
        * canonical constructor or accessor methods are to validate constructor

            vromero Vicente Arturo Romero Zaldivar
            dbessono Dmitry Bessonov
            Gavin Bierman
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: