Java clone()??????????÷?
???????????? ???????[ 2013/12/6 10:53:25 ] ????????
????????????a1.name??a2.name??hash?????@757aef?????????clone??name???????clone?????????????e?????????clone??
public Object clone() {
A o = null;
try {
o = (A) super.clone();
o.name=(String[])name.clone();//???????^_^
} catch (CloneNotSupportedException e) {
e.printStackTrace();
}
return o;
}
|
????????????????
????a1.name=[Ljava.lang.String;@757aef
????a1.name=a1
????a2.name=[Ljava.lang.String;@d9f9c3
????a2.name=b1
?????????????Class A??????????????????????Vector??洢???????????????????clone?????
public class A implements Cloneable {
public String name[];
public Vector<B> claB;
public A(){
name=new String[2];
claB=new Vector<B>();
}
public Object clone() {
A o = null;
try {
o = (A) super.clone();
o.name==(String[])name.clone();//???clone
o.claB=new Vector<B>();//??clone???е???
for(int i=0;i<claB.size();i++){
B temp=(B)claB.get(i).clone();//???Class B????????clone????
o.claB.add(temp);
}
} catch (CloneNotSupportedException e) {
e.printStackTrace();
}
return o;
}
}
|
???????????????????????漰???????????????????SPASVOС??(021-61079698-8054)?????????????????????????