package com.cm.common.utils;

import java.io.*;
import java.util.ArrayList;
import java.util.List;

/**
 * When you feel like quitting. Think about why you started
 * 当你想要放弃的时候，想想当初你为何开始
 *
 * @ClassName: ArrayListUtil
 * @Description: 列表工具
 * @Author: WangGeng
 * @Date: 2020/8/24 17:25
 * @Version: 1.0
 **/
public class ArrayListUtil {

    public static <T extends Serializable> List<T> deepClone(List<? extends Serializable> sourceList, Class<T> clazz) {
        ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
        try {
            ObjectOutputStream out = new ObjectOutputStream(byteOut);
            out.writeObject(sourceList);
            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;
    }

}
