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