< prev index next >

src/java.base/share/classes/java/io/Serializable.java

Print this page

126  * is read from the stream should implement this special method with the
127  * exact signature.
128  *
129  * <PRE>
130  * ANY-ACCESS-MODIFIER Object readResolve() throws ObjectStreamException;
131  * </PRE><p>
132  *
133  * This readResolve method follows the same invocation rules and
134  * accessibility rules as writeReplace.<p>
135  *
136  * Enum types are all serializable and receive treatment defined by
137  * the <a href="{@docRoot}/../specs/serialization/index.html"><cite>
138  * Java Object Serialization Specification</cite></a> during
139  * serialization and deserialization. Any declarations of the special
140  * handling methods discussed above are ignored for enum types.<p>
141  *
142  * Record classes can implement {@code Serializable} and receive treatment defined
143  * by the <a href="{@docRoot}/../specs/serialization/serial-arch.html#serialization-of-records">
144  * <cite>Java Object Serialization Specification,</cite> Section 1.13,
145  * "Serialization of Records"</a>. Any declarations of the special
146  * handling methods discussed above are ignored for record types.<p>









147  *
148  * The serialization runtime associates with each serializable class a version
149  * number, called a serialVersionUID, which is used during deserialization to
150  * verify that the sender and receiver of a serialized object have loaded
151  * classes for that object that are compatible with respect to serialization.
152  * If the receiver has loaded a class for the object that has a different
153  * serialVersionUID than that of the corresponding sender's class, then
154  * deserialization will result in an {@link InvalidClassException}.  A
155  * serializable class can declare its own serialVersionUID explicitly by
156  * declaring a field named {@code "serialVersionUID"} that must be static,
157  * final, and of type {@code long}:
158  *
159  * <PRE>
160  * ANY-ACCESS-MODIFIER static final long serialVersionUID = 42L;
161  * </PRE>
162  *
163  * If a serializable class does not explicitly declare a serialVersionUID, then
164  * the serialization runtime will calculate a default serialVersionUID value
165  * for that class based on various aspects of the class, as described in the
166  * <a href="{@docRoot}/../specs/serialization/index.html"><cite>Java Object Serialization

126  * is read from the stream should implement this special method with the
127  * exact signature.
128  *
129  * <PRE>
130  * ANY-ACCESS-MODIFIER Object readResolve() throws ObjectStreamException;
131  * </PRE><p>
132  *
133  * This readResolve method follows the same invocation rules and
134  * accessibility rules as writeReplace.<p>
135  *
136  * Enum types are all serializable and receive treatment defined by
137  * the <a href="{@docRoot}/../specs/serialization/index.html"><cite>
138  * Java Object Serialization Specification</cite></a> during
139  * serialization and deserialization. Any declarations of the special
140  * handling methods discussed above are ignored for enum types.<p>
141  *
142  * Record classes can implement {@code Serializable} and receive treatment defined
143  * by the <a href="{@docRoot}/../specs/serialization/serial-arch.html#serialization-of-records">
144  * <cite>Java Object Serialization Specification,</cite> Section 1.13,
145  * "Serialization of Records"</a>. Any declarations of the special
146  * handling methods discussed above, except {@code writeReplace},
147  * are ignored for record types.<p>
148  *
149  * Value classes can implement {@code Serializble} and receive the treatment defined
150  * by the <a href="{@docRoot}/../specs/serialization/serial-arch.html#serialization-of-value-objects">
151  * <cite>Java Object Serialization Specification,</cite> Section 1.14,
152  * "Serialization of Value Objects"</a>. Any declarations of the special
153  * handling methods discussed above, except {@code writeReplace},
154  * are ignored for value classes. Value classes implementing {@link Externalizable}
155  * and not using {@code writeReplace} are not supported.<p>
156  *
157  * The serialization runtime associates with each serializable class a version
158  * number, called a serialVersionUID, which is used during deserialization to
159  * verify that the sender and receiver of a serialized object have loaded
160  * classes for that object that are compatible with respect to serialization.
161  * If the receiver has loaded a class for the object that has a different
162  * serialVersionUID than that of the corresponding sender's class, then
163  * deserialization will result in an {@link InvalidClassException}.  A
164  * serializable class can declare its own serialVersionUID explicitly by
165  * declaring a field named {@code "serialVersionUID"} that must be static,
166  * final, and of type {@code long}:
167  *
168  * <PRE>
169  * ANY-ACCESS-MODIFIER static final long serialVersionUID = 42L;
170  * </PRE>
171  *
172  * If a serializable class does not explicitly declare a serialVersionUID, then
173  * the serialization runtime will calculate a default serialVersionUID value
174  * for that class based on various aspects of the class, as described in the
175  * <a href="{@docRoot}/../specs/serialization/index.html"><cite>Java Object Serialization
< prev index next >