美文网首页
java deepclone without implement

java deepclone without implement

作者: 薛云龙 | 来源:发表于2017-02-07 18:37 被阅读8次
    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());
    

    这样做的前提是对象以及对象内部所有引用到的对象都是可串行化的.

    相关文章

      网友评论

          本文标题:java deepclone without implement

          本文链接:https://www.haomeiwen.com/subject/qoemittx.html