句一到句四是连续的一段,其中的句二与句三我怎么看都不明白,求翻译,谢谢。。句一: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.

解决方案 »

  1.   

    句二:子类可以访问父类中的public, protected, 或者package(如果子类和父类在一个包中) field,所以被serialized的子类需要这些信息,以免在deserialized之后执行某些方法的时候发生NullPointerException之类的异常;在父类不会被自动serialized的情况下,子类需要为这些信息的保存负责。一种方法:"just substitute the subclass everywhere your code is expecting the superclass type" -- Head First Java我的疑问:如果在子类中有类似super.instanceField之类的调用,子类应该怎么来保存这个super的instanceField信息呢?---------------------------------
    句三:首先,对于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信息的保存负责吗?=======================
    以上是我的理解和疑问,期待更为明确的解释
      

  2.   

    要允许不可序列化类的子类型序列化,可以假定该子类型负责保存和恢复超类型的公用 (public)、受保护的 (protected) 和(如果可访问)包 (package) 字段的状态。仅在子类型扩展的类有一个可访问的无参数构造方法来初始化该类的状态时,才可以假定子类型有此职责。如果不是这种情况,则声明一个类为可序列化类是错误的。该错误将在运行时检测到。 
    唉,还是自己搞定了。。