创建您自己的
Serializablecookie类,
implementsSerializable然后
cookie在构造过程中复制属性。像这样:
public class Serializablecookie implements Serializable { private String name; private String path; private String domain; // ... public Serializablecookie(cookie cookie) { this.name = cookie.getName(); this.path = cookie.getPath(); this.domain = cookie.getDomain(); // ... } public String getName() { return name; } // ...}确保所有属性本身也可序列化。除了基元之外,
String该类本身例如已经是
implements Serializable,因此您不必担心。
另外,您也可以包装/装饰
cookie作为一个
transient属性(这样不会被序列化),并覆盖
writeObject()和
readObject()方法相应。就像是:
public class Serializablecookie implements Serializable { private transient cookie cookie; public Serializablecookie(cookie cookie) { this.cookie = cookie; } public cookie getcookie() { return cookie; } private void writeObject(ObjectOutputStream oos) throws IOException { oos.defaultWriteObject(); oos.writeObject(cookie.getName()); oos.writeObject(cookie.getPath()); oos.writeObject(cookie.getDomain()); // ... } private void readObject(ObjectInputStream ois) throws ClassNotFoundException, IOException { ois.defaultReadObject(); cookie = new cookie(); cookie.setName((String) ois.readObject()); cookie.setPath((String) ois.readObject()); cookie.setDomain((String) ois.readObject()); // ... }}最后,在中使用该类
List。



