A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
Programmer Certification (SCJP/OCPJP)
Joined: Dec 04, 2008
Jan 10, 2009 09:20:51
public static void main(
SpecialSerial s=new SpecialSerial();
System.out.println(++s.z + " ");
System.out.println(s2.y+ " "+s2.z);
class SpecialSerial implements Serializable
transient int y=7;
static int z=9;
output is:10 0 10 how as we know transient and static dont serialize therefore i think it should be 10 0 0
Joined: Jan 09, 2009
Jan 10, 2009 10:44:17
I think that the static member is not being serialized. The deserialized object doesn't have a "z" value. You can see it debugging the code.
But, since "z" is static and belongs to the class (not to the instances), its value is always there regardless new instances of the class;
Am I right?
Joined: Oct 16, 2008
Jan 10, 2009 10:55:56
Yes you are right Rafael, static variable is not being written on file, not being read from file, it will not loose its value as it is class variable, it will not depend on instance objects being serialized here.
I agree. Here's the link:
what happens when try to serialize static variable
Why static variable serialized here?
Serialization SCJP KS && BB
question about serializable
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2015