代码:
public class NodeType {
public int value;
public NodeType next;
public NodeType(){
value = 0;
next = null;
}
public void printFollowingNodesInOrder(){
System.out.println(this.value);
while(this.next != null){
this.next.printFollowingNodesInOrder();
}
}
}
测试类:
public class TestClass {
public static void main(String[] args){
NodeType nodeOne = new NodeType();
NodeType nodeTwo = new NodeType();
NodeType nodeThree = new NodeType();
nodeOne.value = 1;
nodeTwo.value = 2;
nodeThree.value = 3;
nodeOne.next = nodeTwo;
nodeTwo.next = nodeThree;
nodeOne.printFollowingNodesInOrder();
}
}
当我运行这个main方法时,方法似乎在3之后没有退出。输出为:1 2 3 3 3 3 3 3 3
谁能看出问题出在哪里?