由于我们可以通过覆盖writeObject()和readObject()来覆盖默认的序列化过程,那么Externalizable接口的需求是什么?
以下代码无法编译:
class Super
{
int i = 0;
Super(String text)
{
i = 1;
}
}
class Sub extends Super
{
Sub(String text)
{
------------LINE 14------------
i = 2;
}
public static void main(String args[])
{
Sub sub = new Sub("Hello");
System.out.println(sub.i);
}
}
Run Code Online (Sandbox Code Playgroud)
但是当我super(text)在第14行添加时,它工作正常.为什么会这样?