Sunday, January 8, 2012

The Serializable Interface

The Serializable interface is a tagging interface, which means it does not have any methods
in it. A class implements Serializable to let the JVM know that instances of the class
can be serialized. There is no extra work on your part to make a class serializable because
there are no methods in the interface. Your main concern with implementing Serializable
is ensuring that all the fi elds in your class are also Serializable . If an attempt is
made to serialize an object and a fi eld is reached during the serialization process that is not
serializable, the JVM throws a NotSerializableException and the serialization fails. The
compiler does not verify whether or not your fi elds are Serializable . Denote a fi eld as
transient (using the transient keyword) to tell the JVM to ignore the fi eld during the serialization
and deserialization process.

No comments:

Post a Comment