Reputation: 113
How we can serialize/deserialize a class in java with keeping its singleton nature in the application. Suppose I have serialized a class on every re-deployment of my application with updated values which i want to deserialize later.
Upvotes: 0
Views: 265
Reputation: 469
yes you can do it my implementing
1) instance of the class as static
public static Singleton instance = new Singleton();
2) you have to add private constructor
private Singleton()
{
// private constructor
}
3) You have to declare method by which you can access the declared obj
// implement readResolve method
protected Object readResolve()
{
return instance;
}
Upvotes: 1