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

java.lang.Record should be declared with an explicit constructor

    XMLWordPrintable

Details

    • CSR
    • Resolution: Approved
    • P2
    • 14
    • core-libs
    • None
    • source
    • minimal
    • Pre-GA change to a preview feature.
    • Java API
    • SE

    Description

      Summary

      The type java.lang.Record should use an explicit constructor rather than a default one.

      Problem

      Relying on a default constructor is not prudent for platform classes.

      Solution

      Add an explicit protected constructor.

      Specification

      --- old/src/java.base/share/classes/java/lang/Record.java   2020-01-06 13:47:31.740871560 -0800
      +++ new/src/java.base/share/classes/java/lang/Record.java   2020-01-06 13:47:31.552777567 -0800
      @@ -91,6 +91,11 @@
                                    essentialAPI=true)
       public abstract class Record {
           /**
      +     * Constructor for record classes to call.
      +     */
      +    protected Record() {}
      +
      +    /**
            * Indicates whether some other object is "equal to" this one.  In addition
            * to the general contract of {@link Object#equals(Object)},
            * record classes must further participate in the invariant that when

      Attachments

        Issue Links

          Activity

            People

              darcy Joe Darcy
              darcy Joe Darcy
              Chris Hegarty
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: