Using readResolve method to create a Serializable Singleton

0

The 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;  } }

Read more »

0 comments:

Post a Comment

© Zone817. Powered by Blogger.