Java引用的问题,求助
对于java链表指针,有一个疑惑,有没有同学帮忙解答一下
class Node{
int val;
Node next;
public Node(int x){
this.val = x;
}
}
public class Test {
public static void main(String[] args) {
Node n1 = new Node(3);
Node n2 = new Node(4);
Node n3 = new Node(5);
n1.next = n2;
n2.next = n3;
n2 = null;
System.out.println(n1.next==null);//false
}
} 对于链表n1->n2->n3,当我设置n2=null,为什么n1.next依然存在,并不为null?有时候刷算法题经常遇到这样的困惑