1234567891011121314151617181920212223242526272829303132 |
- package com.kmall.admin.haikong.utils;
- import java.io.*;
- import java.util.Collection;
- import java.util.List;
- /**
- * 深拷贝工具类
- * @author lhm
- * @createDate 2021-12-21
- */
- public class DeepCopyUtils {
- public static <T> Collection<T> depCopy(Collection<T> srcList) {
- ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
- try {
- ObjectOutputStream out = new ObjectOutputStream(byteOut);
- out.writeObject(srcList);
- ByteArrayInputStream byteIn = new ByteArrayInputStream(byteOut.toByteArray());
- ObjectInputStream inStream = new ObjectInputStream(byteIn);
- List<T> destList = (List<T>) inStream.readObject();
- return destList;
- } catch (IOException e) {
- e.printStackTrace();
- } catch (ClassNotFoundException e) {
- e.printStackTrace();
- }
- return null;
- }
- }
|