五分钟源码Java【Serializable接口I】
public interface Serializable {
}
/**
* Serializability of a class is enabled by the class implementing the
* java.io.Serializable interface. Classes that do not implement this
* interface will not have any of their state serialized or
* deserialized. All subtypes of a serializable class are themselves
* serializable. The serialization interface has no methods or fields
* and serves only to identify the semantics of being serializable.
*/
译:
实现java.io.Serializable
接口的类将具有序列化的能力。
没有实现这个接口的类,他们的任何状态都不会被序列化和反序列化。
所有可序列化的类的子类都是可序列化的。
序列化接口没有方法和属性,仅用于识别可序列化的语义。
/** 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 error will be detected at
* runtime.
译:
为了允许不可序列化的类的子类被序列化,子类将承担保存和恢复超类的public、protected、package fields(如何可以访问)的状态的责任。
只有当父类中有一个可访问的无参构造函数来初始化类的状态时,子类才可以承担这个责任。
如果不是这种情况,声明一个类可序列化时将会出错。
这个错误将在运行时被检测到。