Deep and shallow clones of prototype mode

Deep clone the core code:

public Object deepclone () throws IOException, ClassNotFoundException{
//将对象写入流中
ByteArrayOutputStream bao=new ByteArrayOutputStream();
ObjectOutputStream oos=new ObjectOutputStream(bao);
oos.writeObject(this);

//将对象从流中取出
ByteArrayInputStream bis=new ByteArrayInputStream(bao.toByteArray());
ObjectInputStream ois=new ObjectInputStream(bis);
return(ois.readObject());
}

 

Shallow clone core code:

ublic Object clone(){
Email clone=null;

try {
clone=(Email)super.clone();
} catch (CloneNotSupportedException e) {
// TODO Auto-generated catch block
System.out.println("Clone failure");
}
return clone;
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324944908&siteId=291194637