(java)关于new一个对象的生命周期
guide哥,您好啊。这个问题困惑了我好几天。
想问下new一个对象后,这个对象的生命周期是什么时候结束呢?
例如下面这个代码 我在方法里new了一个Node node对象,那这个node会是在调用方法后就结束生命周期吗?还是其他的时间节点呢?
希望guide哥给出我这个迷途小菜鸟一点知道哈~~~谢谢啦~~
public class SuperLink {
//链表的头部
public Node head;
//游标
public int currentIndex = -1;
//增加数据的方法,头插
public void add(Integer data) {
if (head == null) {
head = new Node(data, null);
} else {
//创建一个指向头部的node
Node node = new Node(data, head);
//新的node变成头head
head = node;
}
currentIndex++;
}
}
Node类
public class Node {
public Integer data;
public Node next;
public Node(){
}
public Node(Integer data, Node next) {
this.data = data;
this.next = next;
}
public Integer getData() {
return data;
}
public void setData(Integer data) {
this.data = data;
}
public Node getNext() {
return next;
}
public void setNext(Node next) {
0 个回答
暂无回答