- /**
- * 深度复制
- */
- public static Serializable deeplyCopy(Serializable src) {
- try {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- ObjectOutputStream oos = new ObjectOutputStream(baos);
- oos.writeObject(src);
- oos.close();
- baos.close();
- ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
- ObjectInputStream ois = new ObjectInputStream(bais);
- Serializable copy = (Serializable) ois.readObject();
- ois.close();
- bais.close();
- return copy;
- } catch (Exception e) {
- e.printStackTrace();
- }
- return null;
- }
- //该片段来自于http://www.codesnippet.cn/detail/2207201513205.html
来源: http://www.codesnippet.cn/detail/2207201513205.html