// 用序列化与反序列化实现深克隆
private Object deepClone(Object src) {
Object o = null;
try
{
if (src != null)
{
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(baos);
oos.writeObject(src);
oos.close();
ByteArrayInputStream bais = new ByteArrayInputStream(baos
.toByteArray());
ObjectInputStream ois = new ObjectInputStream(bais);
o = ois.readObject();
ois.close();
}
} catch (IOException | ClassNotFoundException e)
{
e.printStackTrace();
}
return o;
}
Java 序列化方式实现深克隆
最新推荐文章于 2021-11-20 21:34:38 发布