/** * 深度復制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(); }