We can serialize the Singleton Object
without any issue but it will return the new (different) INSTANCE of that
class.
To AVOID this scenario (multiple
instance), implement the readResolve() method and return the Singleton
instance.
private Object readResolve() throws ObjectStreamException{
return singletonInstance;
}
No comments:
Post a Comment