既然是实现的Cloneable接口,应该是一样的啊!请不吝赐教。绝对给分。
各位帅哥靓妹,本人有一个问题始终想不通,如下程序:
public class testclone implements Cloneable{
int a;
double b;
public testclone() {
}
public Object clone(){
try{
return super.clone();
}catch(CloneNotSupportedException e){
System.out.println("cloning not allowed.");
return this;
}
}
}
public class clonedemo {
public clonedemo() {
}
public static void main(String[] args) {
testclone x1=new testclone();
testclone x2;
x1.a=10;
x1.b=20.98;
x2=(testclone)x1.clone();
System.out.println("x1:"+x1.a+" "+x1.b);
System.out.println("x2:"+x2.a+" "+x2.b);
System.out.println(x1.equals(x2));
}
}
为什么最后System.out.println(x1.equals(x2))输出的结果是false;既然是实现的Cloneable接口,应该是一样的啊!请不吝赐教。绝对给分。