< prev index next >

src/java.base/share/classes/java/lang/Record.java

Print this page

 70  * @apiNote
 71  * A record class that {@code implements} {@link java.io.Serializable} is said
 72  * to be a <i>serializable record</i>. Serializable records are serialized and
 73  * deserialized differently than ordinary serializable objects. During
 74  * deserialization the record's canonical constructor is invoked to construct
 75  * the record object. Certain serialization-related methods, such as readObject
 76  * and writeObject, are ignored for serializable records. More information about
 77  * serializable records can be found in the
 78  * <a href="{@docRoot}/../specs/serialization/serial-arch.html#serialization-of-records">
 79  * <cite>Java Object Serialization Specification,</cite> Section 1.13,
 80  * "Serialization of Records"</a>.
 81  *
 82  * @apiNote
 83  * A record class structure can be obtained at runtime via reflection.
 84  * See {@link Class#isRecord()} and {@link Class#getRecordComponents()} for more details.
 85  *
 86  * @spec serialization/index.html Java Object Serialization Specification
 87  * @jls 8.10 Record Types
 88  * @since 16
 89  */


 90 public abstract class Record {
 91     /**
 92      * Constructor for record classes to call.
 93      */
 94     protected Record() {}
 95 
 96     /**
 97      * Indicates whether some other object is "equal to" this one.  In addition
 98      * to the general contract of {@link Object#equals(Object) Object.equals},
 99      * record classes must further obey the invariant that when
100      * a record instance is "copied" by passing the result of the record component
101      * accessor methods to the canonical constructor, as follows:
102      * <pre>
103      *     R copy = new R(r.c1(), r.c2(), ..., r.cn());
104      * </pre>
105      * then it must be the case that {@code r.equals(copy)}.
106      *
107      * @implSpec
108      * The implicitly provided implementation returns {@code true} if
109      * and only if the argument is an instance of the same record class

 70  * @apiNote
 71  * A record class that {@code implements} {@link java.io.Serializable} is said
 72  * to be a <i>serializable record</i>. Serializable records are serialized and
 73  * deserialized differently than ordinary serializable objects. During
 74  * deserialization the record's canonical constructor is invoked to construct
 75  * the record object. Certain serialization-related methods, such as readObject
 76  * and writeObject, are ignored for serializable records. More information about
 77  * serializable records can be found in the
 78  * <a href="{@docRoot}/../specs/serialization/serial-arch.html#serialization-of-records">
 79  * <cite>Java Object Serialization Specification,</cite> Section 1.13,
 80  * "Serialization of Records"</a>.
 81  *
 82  * @apiNote
 83  * A record class structure can be obtained at runtime via reflection.
 84  * See {@link Class#isRecord()} and {@link Class#getRecordComponents()} for more details.
 85  *
 86  * @spec serialization/index.html Java Object Serialization Specification
 87  * @jls 8.10 Record Types
 88  * @since 16
 89  */
 90 @jdk.internal.MigratedValueClass
 91 @jdk.internal.ValueBased
 92 public abstract class Record {
 93     /**
 94      * Constructor for record classes to call.
 95      */
 96     protected Record() {}
 97 
 98     /**
 99      * Indicates whether some other object is "equal to" this one.  In addition
100      * to the general contract of {@link Object#equals(Object) Object.equals},
101      * record classes must further obey the invariant that when
102      * a record instance is "copied" by passing the result of the record component
103      * accessor methods to the canonical constructor, as follows:
104      * <pre>
105      *     R copy = new R(r.c1(), r.c2(), ..., r.cn());
106      * </pre>
107      * then it must be the case that {@code r.equals(copy)}.
108      *
109      * @implSpec
110      * The implicitly provided implementation returns {@code true} if
111      * and only if the argument is an instance of the same record class
< prev index next >