public class T{ static class Node{ int value; Node left = null; Node right = null; public Node(int value){ this.value = value; } } public static void main(String[] args) { // TODO Auto-generated method stub Node node = new Node(0); T bt = new T(); bt.test(node); System.out.println(node.value); } public void test(Node node){ node.value = 3; node = new Node(5); } }
输出结果3
传递到函数里面的node相当一个新的指向原node的引用,改变这个引用的指向不会影响原Node