Enums are considered best way for singletons and one of reasons for this is that it implicitly inherits Serializable
.
But how enums prevents de-serialization problem of singletons?
See Question&Answers more detail:osEnums are considered best way for singletons and one of reasons for this is that it implicitly inherits Serializable
.
But how enums prevents de-serialization problem of singletons?
See Question&Answers more detail:osThe serialization mechanism handles them in a special, specific way. But traditional singletons can be deserialized fine by defining a readResolve()
method that returns the unique instance. See http://www.oodesign.com/singleton-pattern.html for an example.