`
v5qqbrowser
  • 浏览: 356141 次
文章分类
社区版块
存档分类
最新评论

利用串行化来做深复制

 
阅读更多
public Object deepClone()
{
 //将对象写到流里
 ByteArrayOutoutStream bo=new ByteArrayOutputStream();
 ObjectOutputStream oo=new ObjectOutputStream(bo);
 oo.writeObject(this);
 //从流里读出来
 ByteArrayInputStream bi=new ByteArrayInputStream(bo.toByteArray());
 ObjectInputStream oi=new ObjectInputStream(bi);
 return(oi.readObject());
}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics