我正在编写一个简单的代码,并且在第 2 行的以下代码中收到 StackOverflowError:Tmp4 t = new Tmp4 ();
如果我省略第 6 行(初始化p
)或省略第 2 行,我不会收到错误消息。而且我没有进行递归调用。
我想问为什么它会给出这样的错误。在省略第 2 行或第 6 行时,它不会给出 StackOverflowError。
此外,它仅在我的系统上提供或代码有问题。
谢谢。
public class Tmp4 {
Tmp4 t = new Tmp4 ();
public static void main(String[] args) {
System.out.println("main");
Tmp4 p = new Tmp4 ();
System.out.println("main2");
}
}