0

我有这段代码,我想知道为什么我的变量 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();
 }

}

4

0 回答 0