对象序列化实现深度克隆
生活随笔
收集整理的這篇文章主要介紹了
对象序列化实现深度克隆
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
/*** Discription:[深度復制方法,需要對象及對象所有的對象屬性都實現序列化]*/public BaseGUIBean deepClone() throws Exception {BaseGUIBean distObject = null;// 將該對象序列化成流,因為寫在流里的是對象的一個拷貝,而原對象仍然存在于JVM里面。所以利用這個特性可以實現對象的深拷貝ByteArrayOutputStream bos = new ByteArrayOutputStream();ObjectOutputStream oos = new ObjectOutputStream(bos);oos.writeObject(this);// 將流序列化成對象ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());ObjectInputStream ois = new ObjectInputStream(bis);distObject = (BaseGUIBean) ois.readObject();return distObject;}
總結
以上是生活随笔為你收集整理的对象序列化实现深度克隆的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: PPT快速制作精美3D柱状图
- 下一篇: 巧妙解决:access denied (