最近对Java中两个类交叉引用的问题有点迷惑,如下代码类A public class A { private B b; A(){ b = new B(); System.out.println("class A is building"); } }类Bpublic class B { private A a; B(){ a = new A(); System.out.println("class B is building"); }}测试类 public class Test { public static void main(String[] args) { A a = new A(); } }测试方法运行后,提示Exception in thread "main" java.lang.StackOverflowError请各位大哥帮忙分析分析
添加回答
举报
0/150
提交
取消