Java深度克隆

@SuppressWarnings("unchecked")
public static  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;
}

你可能感兴趣的:(Java深度克隆)