Enum constants are serialized differently than ordinary
serializable or externalizable objects. The serialized form of an enum constant
consists solely of its name; field values of the constant are not present in
the form.
To serialize an enum constant, ObjectOutputStream writes the
value returned by the enum constant's name method.
To deserialize an enum
constant, ObjectInputStream reads the constant name from the stream; the
deserialized constant is then obtained by calling the java.lang.Enum.valueOf
method, passing the constant's enum type along with the received constant name
as arguments.
Important points:
enum constants are serialization
cannot be customized with writeObject, readObject, readObjectNoData,
writeReplace, and readResolve methods, enum types are ignored during
serialization and deserialization by these methods.
All enum types have a fixed serialVersionUID
of 0L.
No comments:
Post a Comment