list的深度复制

public class DeepCopyUtils {

public static <T> List<T> deepCopyList(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);
@SuppressWarnings("unchecked")
List<T> dest = (List<T>) in.readObject();
return dest;
}

}
posted @ 2020-02-04 15:51  Husir_Boky  阅读(916)  评论(0)    收藏  举报