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(如何可以访问)的状态的责任。
只有当父类中有一个可访问的无参构造函数来初始化类的状态时,子类才可以承担这个责任。
如果不是这种情况,声明一个类可序列化时将会出错。
这个错误将在运行时被检测到。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值