当我查看Java的代码示例时,我看到了一段奇怪的代码:
public class Application {
public static void main(String[] args) {
String[] x = {"A"};
String[] y = x;
x[0] = "B";
System.out.print(x[0] + " " + y[0]);
}
}
我不明白为什么结果是"B B"是正确的。当我创建和初始化数组x和y,并且将数组x的零元素分配为B时,我认为答案应该是“B A”。