• Post Reply Bookmark Topic Watch Topic
  • New Topic

Doubt in Serializable classes and what we can do with them  RSS feed

 
John McDowell
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is a line in Head FIrst Java 2nd edition that says that we are allowed to add or remove classes in the inheritance tree, without affecting the ability of the objects from a class to be deserialized, but there is another line that says that we should not let the class
whose objects are serialized move up or down in the inheritance tree.

Does this mean that we can only add/delete classes which are 1)at the same level 2)a descendant of the class
with serializable objects

Does this mean that we cannot delete classes that are ancestors of the class whose objects are serialized?(Ofcourse taking the precaution that the child of the deleted ancestor class now becomes the child of the parent of the deleted ancestor class)
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
John McDowell wrote:Does this mean that we cannot delete classes that are ancestors of the class whose objects are serialized?

That's what I'd assume. And for the reason, just think about what serialization means:

It means that somewhere, sometime, someone probably saved a copy of an object in a file. And if you ever need to access that copy, you'd better be able to reconstruct it. So if you ever change the structure so that something significant is different, the serialization process will raise an Exception.

That said, the need for inserting or removing classes from a hierarchy is (or should be) pretty rare.

HIH

Winston
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!