• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Serialization Question

 
Nigel Browne
Ranch Hand
Posts: 703
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I hope someone can explain the result I get from running the following code
Running this code I would expect the object m to be serialized with a counter value of 2. However when I run the following code I get the result of 0


Can someone please explain the result I am getting and how to resolve the issue.
 
Joe Ess
Bartender
Posts: 9256
9
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Static members of a class are not persisted. When you declare a member of a class to be "static", you are tying its state to the class rather than a particular instance of that class. Serialization is designed to persist the state of an instance, so it ignores static members (and members flagged with the "transient" keyword).
In your case, your Model class gets reloaded when the VM goes away and starts back up so the counter starts back at 0.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic