Sunday, October 31, 2010

Serializable Singleton

In a class write below code to prevent singleton class from losing its behavior if you make it serializable.

protected Object readResolve(){
    return singletonObj;
}

Deserialization creates another object instance, so to avoid that situation this needs to be done.

No comments:

Post a Comment