• Post Reply Bookmark Topic Watch Topic
  • New Topic

Serialization : Static varibales are getting old values after deserialization  RSS feed

 
Sushil Jamsandekar
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am running below program and getting output as given below. As per my understanding static variables are not serialized, but it seems they are getting serialized. Where I am making a mistake?



And ouput of above program is

private - protected - public
private static - protected static - public static
private - protected - null
private static - protected static - public static

Thanks,
Sushil
 
Matthew Brown
Bartender
Posts: 4568
9
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
They aren't serialized, but static variables belong to the class. The original object and the deserialized object are of the same class, so will see the same values.

This would probably be more obvious if you referred to the static fields using SerializationTest.staticState, etc. You should avoid ever using an object instance to access a static variable or method as it is misleading.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!