Reputation: 497
there are lots of toturials about enum and serialization, I also read the article in sun, but not able to find how to serialize it.
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.
any example will appreciate.
Upvotes: 2
Views: 2727
Reputation: 82559
All enum types implicitly extend java.lang.Enum
which already implements Serializable. Thus you have no specific action to take, it's already done for you.
Upvotes: 4