深浅clone问题
package test;
public class CloneTest1 implements Cloneable {
java.util.Date date;
String s = "abc";
public Object clone() {
try {
return super.clone();
} catch (CloneNotSupportedException ex) {
return null;
}
}
public static void main(String[] args){
CloneTest1 src=new CloneTest1();
CloneTest1 des=(CloneTest1)src.clone();
System.out.println(src.s);
System.out.println(des.s);
des.s = "dddddddd";
System.out.println(src.s);
System.out.println(des.s);
}
}
为什么输入为
abc
abc
abc
dddddddd
浅clone指向同一个引用,为什么不是
abc
abc
dddddddd
dddddddd