死所有,
我有以下内容:
class test {
int x = 6;
int y = 7;
private int getX() {
return x;
}
private int getY() {
return y;
}
public test copy() {
test myTest = new test();
myTest.x = getX();
myTest.y = getY();
return myTest;
}
}
但是,当我执行时:
test a = new test();
test b = a.copy();
b.x = 17;
System.out.println(a.x);
结果仍然是 17。但是,深度复制不应该阻止这种情况吗?
有谁能帮助我吗?