22 - Java Serialization with Enum Constants - Code Demo 1

@backstreetbrogrammer -------------------------------------------------------------------------------- Chapter 09 - Serialization with Enum Constants -------------------------------------------------------------------------------- As per Java specifications, Enum constants are serialized differently than ordinary serializable objects. To serialize an enum constant, ObjectOutputStream writes the value returned by the enum constant’s name() method. name() is an instance method which returns the name of the instance. To deserialize an enum constant, ObjectInputStream reads the constant name from the stream; the deserialized constant is then obtained by calling the valueOf() method, passing the constant’s enum type along with the received constant name as arguments. valueOf() is a static method taking a String and returning the enum instance with that name. Few more points to take note of: - enum types have a fixed serialVersionUID of 0L and cannot be changed - pr
Back to Top