ReadObject is returning null values
I have the following class design. My engine attribute is coming as null
each time,even though I have read its value from readObject
public class Car implements Serializable {
private int regId;
transient Engine e;
private void writeObject(ObjectOutputStream oos) {
try {
oos.defaultWriteObject();
oos.writeInt(e.horsePower);
} catch (Exception e) {
e.printStackTrace();
}
}
private void readObject(ObjectInputStream oxos) {
try {
oxos.defaultReadObject();
Engine e = new Engine(oxos.readInt());
} catch (Exception e) {
e.printStackTrace();
// TODO: handle exception
}
}
public class Engine {
int horsePower;
}
No comments:
Post a Comment