public static <T> List<T> deepCopy(List<T> src) {
ByteArrayOutputStream byteout = null;
ObjectOutputStream out = null;
ByteArrayInputStream bytein = null;
ObjectInputStream in = null;
try {
byteout = new ByteArrayOutputStream();
out = new ObjectOutputStream(byteout);
out.writeObject(src);
bytein = new ByteArrayInputStream(byteout.toByteArray());
in = new ObjectInputStream(bytein);
@SuppressWarnings("unchecked")
List<T> dest = (List<T>) in.readObject();
return dest;
} catch (ClassNotFoundException | IOException e) {
e.printStackTrace();
return null;
} finally {
if (byteout!=null) {
try {
byteout.close();
} catch (IOException ignore) {}
}
if (out!=null) {
try {
out.close();
} catch (IOException ignore) {}
}
if (bytein!=null) {
try {
bytein.close();
} catch (IOException ignore) {}
}
if (in!=null) {
try {
in.close();
} catch (IOException ignore) {}
}
}
}