Java中的代码:为什么我不能将传入的对象分配给方法中的新值?
private BiNode root = null;
//constructor
BST(int[] r) {
BiNode s = new BiNode(r[0], null, null);
test(root, s);
}
private void test(BiNode head, BiNode s){
head = s;
if (head != null)
System.out.println("head is not null");
if (root == null)
System.out.println("root is null");
}
输出:
head is not null
root is null
为什么root
不在test
方法等于head
?
你从来没有设置'root'等于任何东西。研究按价值传递。 –