@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
2 views
833
227
3 days ago 01:31:39 1
КАК ИРАН СТАЛ ТАКИМ? “Исламская революция“/новое Средневековье/станет ли Россия вторым Ираном?
5 days ago 00:09:29 1
Диверсанты в Рязани хотели отключить от жизнеобеспечивающего ресурса.