/**
* @Description: List深度克隆
* @Param: source 源集合
* @Return: java.util.List<T>
* @Author: CWR
* @Date: 2019/12/26 16:17
*/
public static <T> List<T> deepCopy(List<T> source) throws IOException, ClassNotFoundException {
ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
ObjectOutputStream out = new ObjectOutputStream(byteOut);
out.writeObject(source);
ByteArrayInputStream byteIn = new ByteArrayInputStream(byteOut.toByteArray());
ObjectInputStream in = new ObjectInputStream(byteIn);
@SuppressWarnings("unchecked")
List<T> result = (List<T>) in.readObject();
return result;
}
克隆的对象必须要实现Serializable接口,不然会报错。