句一到句四是连续的一段,其中的句二与句三我怎么看都不明白,求翻译,谢谢。。句一:To allow subtypes of non-serializable classes to be serialized,
句二:the subtype may assume responsibility for saving and restoring the state of the supertype's public, protected, and (if accessible) package fields.
句三:The subtype may assume this responsibility only if the class it extends has an accessible no-arg constructor to initialize the class's state.
句四:It is an error to declare a class Serializable if this is not the case.
句二:the subtype may assume responsibility for saving and restoring the state of the supertype's public, protected, and (if accessible) package fields.
句三:The subtype may assume this responsibility only if the class it extends has an accessible no-arg constructor to initialize the class's state.
句四:It is an error to declare a class Serializable if this is not the case.
句三:首先,对于serializable subclass which extends non-serializable super-class,其de-serialization过程为:
"When an object is deserialized and its superclass is not serializable, the superclass constructor will run just as though a new object of that type were being created." -- Head First Java
所以考察其superclass的constructor情况:
1,没有accessable的constructor -- 此情况下父类信息无需保存,因为deserialized之后的子类也用不到这些信息
2,有accessable的non-argue的constructor -- 此情况下子类需要为父类中的信息保存负责
3,有accessable的constructor,但是没有non-argue的 -- 此情况下在子类的constructor中都会写明如何创建父类对象,因此子类无需再为父类信息保存负责我的疑问:第三种情况中,如果父类有一个field (e.g. superInstanceField),这个field不会在父类的constructor中被初始化,但是该field却是public的 -- 在这种情况下难道子类不需要为这个field信息的保存负责吗?=======================
以上是我的理解和疑问,期待更为明确的解释
唉,还是自己搞定了。。