/**
     * 深度复制list对象,先序列化对象,再反序列化对象
     *
     * @param src 需要复制的对象列表
     * @return 返回新的对象列表
     * @throws IOException 读取Object流信息失败
     * @throws ClassNotFoundException 泛型类不存在
     */
    public static <T> List<T> deepCopy(List<T> src)
        throws IOException, ClassNotFoundException
    {
        ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
        ObjectOutputStream out = new ObjectOutputStream(byteOut);
        out.writeObject(src);
        ByteArrayInputStream byteIn = new ByteArrayInputStream(byteOut.toByteArray());
        ObjectInputStream in = new ObjectInputStream(byteIn);
        return (List<T>)in.readObject();
    }

 

相关文章:

  • 2021-10-09
  • 2022-12-23
  • 2021-11-23
  • 2021-05-31
  • 2021-06-12
  • 2021-07-27
  • 2021-11-21
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-01-19
  • 2022-02-09
  • 2021-10-12
  • 2021-11-23
相关资源
相似解决方案