答案是不能。
事实证明,在类内部一直实例化自身会造成栈溢出,测试代码如下。
1 public class test1 { 2 3 /** 4 * @param args 5 */ 6 public static void main(String[] args) { 7 // TODO Auto-generated method stub 8 test1.A aa = new test1().new A(); 9 test1.A b = aa.getA(); 10 System.out.println("ok"); 11 } 12 13 class A{ 14 15 private A a = new A(); 16 17 public A getA(){ 18 19 return a;