<pre name="code" class="java">/**
申明:使用序列化进行深复制,凡是涉及到需要复制的类都必须实现Serializable接口。
*/
public Object deepCopy()
throws Exception
{
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(bos);
oos.writeObject(this);
ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
ObjectInputStream ois = new ObjectInputStream(bis);
return ois.readObject();
}
java的
最新推荐文章于 2024-06-02 22:24:53 发布