我有这段代码,我想知道为什么我的变量x的引用没有修改?它仍指向分配的第一个对象:
public class HelloWorld{
public static void main(String []args){
Object x = new Object();
Object y = x;
mutate(x);
System.out.println(Integer.toHexString(x.hashCode()));
System.out.println(Integer.toHexString(y.hashCode()));
System.out.println(x == x); // true
System.out.println(x == y); // true
}
public static void mutate(Object x) {
x = new String();
}
}