24 Java Serialization with static fields Code Demo
backstreetbrogrammer Chapter 10 Serialization with static fields Static fields are NEVER saved as part of the objects state. We should think of static variables purely as CLASS variables. They have nothing to do with individual instances. And serialization applies only to OBJECTS. Suppose we have 3 instances of a Serializable class , all of which were serialized at different times, and thus all of which were saved when the value of a static variable in the class was different. Now, if static variables were serializable, which of the 3 instances would win OR, Which instances static value would be used to replace the one currently in the one and only class thats currently loaded , This is a problem thats why, static fields are never part of serialization, deserialization process. Jav
|
|