@SuppressWarnings("unchecked")
public static <T extends Serializable> T deepClone(T object) {
T temp = null;
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(baos);
oos.writeObject(object);
ByteArrayInputStream bis = new ByteArrayInputStream(baos.toByteArray());
ObjectInputStream ois = new ObjectInputStream(bis);
temp = (T) ois.readObject();
} catch (Exception e) {
e.printStackTrace();
}
return temp;
}
网友评论