aspose file tools*
The moose likes I/O and Streams and the fly likes Serialization Question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Serialization Question" Watch "Serialization Question" New topic
Author

Serialization Question

Nigel Browne
Ranch Hand

Joined: May 15, 2001
Posts: 673
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

Joined: Oct 29, 2001
Posts: 8968
    
    9

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.


[How To Ask Questions On JavaRanch]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Serialization Question