1
0

DeepCopyUtils.java 914 B

1234567891011121314151617181920212223242526272829303132
  1. package com.kmall.admin.haikong.utils;
  2. import java.io.*;
  3. import java.util.Collection;
  4. import java.util.List;
  5. /**
  6. * 深拷贝工具类
  7. * @author lhm
  8. * @createDate 2021-12-21
  9. */
  10. public class DeepCopyUtils {
  11. public static <T> Collection<T> depCopy(Collection<T> srcList) {
  12. ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
  13. try {
  14. ObjectOutputStream out = new ObjectOutputStream(byteOut);
  15. out.writeObject(srcList);
  16. ByteArrayInputStream byteIn = new ByteArrayInputStream(byteOut.toByteArray());
  17. ObjectInputStream inStream = new ObjectInputStream(byteIn);
  18. List<T> destList = (List<T>) inStream.readObject();
  19. return destList;
  20. } catch (IOException e) {
  21. e.printStackTrace();
  22. } catch (ClassNotFoundException e) {
  23. e.printStackTrace();
  24. }
  25. return null;
  26. }
  27. }