Forums Register Login

Serialization : Static varibales are getting old values after deserialization

+Pie Number of slices to send: Send
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
2
+Pie Number of slices to send: Send
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.
A timing clock, fuse wire, high explosives and a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 554 times.
Similar Threads
serializable problem
iteration
De-serialization
private(?) writeObject/readObject
transient Variable
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 17:44:01.