Using readResolve method to create a Serializable Singleton
Posted by zone817The readResolve method allows a class to replace/resolve the object read from the stream before it is returned to the caller. The following code demonstrates how to create a serializable singleton , using the method.
public class Singleton implements Serializable { static Singleton instance= new Singleton (); private Singleton () { } protected Object readResolve() { return instance; } }
0 comments:
Post a Comment