Effective Java - To maintain the singleton guarantee, you have to declare all instance fields transient and provide a \'readResolve\' method. What do we achieve by declaring
Irrespective of whether I declare the 'state' variable as transient or not ,I get c.getState() gettign printed out as 25. Am I Missing something here?
You replace your deserialized object, because readResolve() returns the private static instance of MySingleton, thus overriding the instance returned by the deserialization.