上面打错了一个地方
在第54条里有
如果一个专门为了继承而设计的类不是可序列化的,那么要编写出可系列化的子类几乎是不可能的。特别地,如果超类没有提供一个可访问的、无参数的构造函数的话,那么子类要做到可系列化是不可能的。
If a class that is designed for inheritance is not serializable, it may be impossible to write a serializable subclass. Specifically, it will be impossible if the superclass does not provide an accessible parameterless constructor.为什么?
在第54条里有
如果一个专门为了继承而设计的类不是可序列化的,那么要编写出可系列化的子类几乎是不可能的。特别地,如果超类没有提供一个可访问的、无参数的构造函数的话,那么子类要做到可系列化是不可能的。
If a class that is designed for inheritance is not serializable, it may be impossible to write a serializable subclass. Specifically, it will be impossible if the superclass does not provide an accessible parameterless constructor.为什么?
解决方案 »
- JNI char*转jstring乱码问题
- 请问java中有多少过时的api,以前的代码程序需要做很大的改动吗??
- JAVA中的eval , 能计算字符串的算数公式(源代码)
- 关于JPanel的repaint问题
- java如何从字符串中提取相应位置的字符??
- 哪个有Struts分页的原代码要完成版(急急急急急急急急急急急急急急急)
- 如何把接收到的"\\u4F60\\u597D"转换成正确的中文形式打出来?
- 请问又没有什么好的国外的论坛,主要关于软件设计、开发方面的可以介绍几个么
- 想用Java写一个俄罗斯方块的程序,请高手给点意见!~~
- 关于比较器的调用方法
- 正在复习scjp。有机部分内容请指导!谢谢!
- 异常输出顺序不同...
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. During deserialization, the fields of non-serializable classes will be initialized using the public or protected no-arg constructor of the class. A no-arg constructor must be accessible to the subclass that is serializable. The fields of serializable subclasses will be restored from the stream. 有几个问题
1.The subtype may assume this responsibility only if the class it extends has an accessible no-arg constructor to initialize the class's state.为什么?运行时错误是怎么产生的?
2.During deserialization, the fields of non-serializable classes will be initialized using the public or protected no-arg constructor of the class.难道子类继承了超类的域以后,不能自己控制该域是否可以序列化,而要看超类有没有提供可访问的无参数构造函数?有点不明白