/**
* 深度复制,复制整个对象及相关联的的内容,前提是该对象所对应的类继承了Serializable
*/
public Serializable deepCopy(Serializable obj){
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(baos);
oos.writeObject(obj);
oos.close();
baos.close();
byte[] bytes = baos.toByteArray();
ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
ObjectInputStream ois = new ObjectInputStream(bais);
Serializable copy = (Serializable) ois.readObject();
ois.close();
bais.close();
return copy ;
} catch (Exception e) {
e.printStackTrace();
}
return null ;
}
* 深度复制,复制整个对象及相关联的的内容,前提是该对象所对应的类继承了Serializable
*/
public Serializable deepCopy(Serializable obj){
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(baos);
oos.writeObject(obj);
oos.close();
baos.close();
byte[] bytes = baos.toByteArray();
ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
ObjectInputStream ois = new ObjectInputStream(bais);
Serializable copy = (Serializable) ois.readObject();
ois.close();
bais.close();
return copy ;
} catch (Exception e) {
e.printStackTrace();
}
return null ;
}