Rhyme/五分鐘源碼Java【Serializable接口I】

五分鐘源碼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(如何可以訪問)的狀態的責任。
只有當父類中有一個可訪問的無參構造函數來初始化類的狀態時,子類纔可以承擔這個責任。
如果不是這種情況,聲明一個類可序列化時將會出錯。
這個錯誤將在運行時被檢測到。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章