I searched the web to find answers to some of the queries related to the enum class in java.
My query is why the default de-serialization was prevented in the enum class. I see that the enum class implements the Serializable interface, but it also has two methods, as shown below:
private void readObject(ObjectInputStream in) throws IOException,
ClassNotFoundException {
throw new InvalidObjectException("can't deserialize enum");
}
private void readObjectNoData() throws ObjectStreamException {
throw new InvalidObjectException("can't deserialize enum");
}
I am more embarrassed to see this class. Any help would be appreciated. Thanks in advance.
I'm more confused since ENUM implements a serializable interface and has the methods described above that throw "throw new InvalidObjectException" ("can deserialize enum"); An exception. so I don’t understand what is above two methods?
Also, the comments above the two methods say "prevent default deserialization", what does this mean?