// Serializable subclass of nonserializable stateful class import java.io.*; public class Foo extends AbstractFoo implements Serializable { private void readObject(ObjectInputStream s) throws IOException, ClassNotFoundException { s.defaultReadObject(); // Manually deserialize and initialize superclass state int x = s.readInt(); int y = s.readInt(); initialize(x, y); } private void writeObject(ObjectOutputStream s) throws IOException { s.defaultWriteObject(); // Manually serialize superclass state s.writeInt(getX()); s.writeInt(getY()); } // Constructor does not use any of the fancy mechanism public Foo(int x, int y) { super(x, y); } }
最近下载更多