• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Statics and serialization

 
Mansukhdeep Thind
Ranch Hand
Posts: 1158
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sir / Madam
Why cannot Static variables be serialized/deserialized? Please educate me.

Regards
Mansukhdeep Singh
 
Naresh Shanmugam
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Serialization is only for instance variables.
Static variables are like class variables, i.e only one copy would be maintained irrespective of number of instances created.
The value of an instance variable might differ for each instance, but not the static variable!!
 
Abimaran Kugathasan
Ranch Hand
Posts: 2066
Clojure IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mansukhdeep Thind wrote:
Why cannot Static variables be serialized/deserialized? Please educate me.


Static members are associated with the class, not the instances, so it does not make sense to include them when serializing an instance.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic