NotSerializableException
为什么我在序列化的类中没有原因A
我有private B b
没有序列化的原因,我知道如果类实现Serializable
所有复合类也必须实现Serializable
/ Externalizable
。
import java.io.*;
public class Test
{
public static void main(String[] args) throws IOException
{
FileOutputStream fileOutput = new FileOutputStream("a.dat");
ObjectOutputStream outputStream = new ObjectOutputStream(fileOutput);
outputStream.writeObject(new A());
fileOutput.close();
outputStream.close();
}
}
class A implements Serializable
{
private int age;
private B b;
}
class B
{
}