I have been searching web to find the answers of some of the queries related to enum class in java.
My query is why default De-serialization has been prevented in enum class. I can see that the enum class implements Serializable interface but it also have 2 methods as 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 confused after seeing this class. Any help will be appreciated. Thanks in advance.
I am more confused since ENUM implements serializable interface itself and have above methods too that throws "throw new InvalidObjectException("can't deserialize enum");" Exception. so i am not getting clear understanding of what above two methods are for ?
Also comments on above two methods says "prevent default deserialization" what does it mean ?