Java Reference
In-Depth Information
private void readObject(ObjectInputStream in)
throws IOException, ClassNotFoundException
{
ObjectInputStream.GetField fields;
fields = in.readFields();
x = fields.get("x1", 0.0);
y = fields.get("y1", 0.0);
double x2 = fields.get("x2", 0.0);
double y2 = fields.get("y2", 0.0);
width = (x2 - x);
height = (y2 - y);
}
private void writeObject(ObjectOutputStream out)
throws IOException
{
ObjectOutputStream.PutField fields;
fields = out.putFields();
fields.put("x1", x);
fields.put("y1", y);
fields.put("x2", x + width);
fields.put("y2", y + height);
out.writeFields();
}
}
Rectangle keeps the serialVersionUID of the original version to declare
that the versions are compatible. Changing fields that would be used
by default serialization is otherwise considered to be an incompatible
change.
To represent each of the old fields that will be found in the serialized
data, you create an ObjectStreamField object. You construct each Ob-
jectStreamField object by passing in the name of the field it represents,
and the Class object for the type of the field it represents. An overloaded
 
Search WWH ::




Custom Search