本页地址:http://blog.csdn.net/lpy3654321/article/details/43054557
java 深clone对象的另一种方法
public static <T> T deepCopy(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); T dest = (T) in.readObject(); return dest; }
前提是,传的对象,以及包含的对象需要都实现 java.io.Serializable 序列化 接口
转载:http://blog.csdn.net/applepop/article/details/5702432
时间: 2024-11-11 16:20:01