在看书,JAVA核心技术卷二里的一节内容
有下面一段枚举类型:
public class Orientation
{
public static final Orientation HORIZONTAL = new Orientation(1);
public static final Orientation VERTICAL = Orientation(2);
private int value;
private Orientation(int v)
{
value = v;
}
}
Orientation original = Orientation.HORIZONTAL;
ObjectOutputStream out = new ObjectOutputStream(,,,);
out.write(original);
out.close();
ObjectInputStream in = new ObjectInputStream(...);
Orientation saved = (Orientation) in.read();
这里说序列化创造了新的对象,saved的值就是Orientation类型一个全新的对象,那么为什么不可将读入流in中的Orientatio读入,等号后还有和意义,还是说读出流out中或者读入流in中根本就没有这个对象。
初学者,谢谢各位传道解惑