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 Collection depCopy(Collection 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 destList = (List) inStream.readObject(); return destList; } catch (IOException e) { e.printStackTrace(); } catch (ClassNotFoundException e) { e.printStackTrace(); } return null; } }