Serialización 101

class Animal {

 public String name;

}

class Dog extends Animal implements Serializable {

  // the rest of the Dog code

}

Because Animal is NOT serializable, any state maintained in the Animal class, even though the state variable is inherited by the Dog, isn’t going to be restored with the Dog when it’s deserialized! The reason is, the (unserialized) Animal part of the Dog is going to be reinitialized just as it would be if you were making a new Dog (as opposed to deserializing one). That means all the things that happen to an object during construction, will happen—but only to the Animal parts of a Dog. In other words, the instance variables from the Dog’s class will be serialized and deserialized correctly, but the inherited variables from the non-serializable Animal superclass will come back with their default/initially assigned values rather than the values they had at the time of serialization.

1 Comentario »

RSS feed de los comentarios de este post. TrackBack URI

Comentar

Captcha
Enter the letters you see above.

Entradas y comentarios feeds. 19 queries. 0.247 seconds.

60920 pages viewed, 15 today
29269 visits, 10 today
FireStats icon Powered by FireStats