G
Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
G
#1 in that list is correct. But #2 ignores that and continues to talk as though serialization and deserialization had some effect on static variables. Here's a better way to state #2:Originally posted by G Marshall:
1. Static variables are NOT serialized
2. If your object is serialized and deserialized on(in?) the same JVM,
your static variable will have the same value when it is deserialized
as when it was serialized.
G
Originally posted by G Marshall:
Paul:
Thank you for uncomplicating this. OK. So I have a static integer variable, whose initial value = 9, that I set to 200 before serializing the instance of the class. Upon deserialization that same static varialble remains at 200, not its inital value of 9. Now with all due respect to you as you are the java guru and I am just a java grasshopper, this sure looks like the static variable is getting serialized!!
:roll:
Originally posted by Henry Wong:
How about change the test to something like this? Set the static integer variable, whose initial value = 9, to 200 *after* serializing the instance of the class.
Upon deserialization, is it the value of 9, which was the value you had when you serialized it? Or is it still 200, the value *after* you serialized it?
Henry
G
In our scenario how does the static variable in the object on computer B know that it should have a value of 200?
Don't get me started about those stupid light bulbs. |