深拷贝工具

public class ObjectUtil {
    public ObjectUtil() {
    }

    public static Object deepCopy(Object orig) throws IOException, ClassNotFoundException {
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        ObjectOutputStream oos = new ObjectOutputStream(bos);
        oos.writeObject(orig);
        oos.flush();
        ByteArrayInputStream bin = new ByteArrayInputStream(bos.toByteArray());
        ObjectInputStream ois = new ObjectInputStream(bin);
        return ois.readObject();
    }
}

 

你可能感兴趣的:(后台)