我的工作和Inner Class概念和編寫下面code_的Java:的StackOverflowError
public class InnerClassConcepts {
private int x = 11;
public static void main(String... args) {
// method local 'x' variable
int x = new InnerClassConcepts().new InnerA().new InnerB().x;
InnerClassConcepts in = new InnerClassConcepts();
InnerA InnerA = in.new InnerA();
InnerA.InnerB xx = in.new InnerA().new InnerB();
System.out.println("InnerClassConcepts`s x = " + in.x);
System.out.println("InnerB`s x = " + xx.x);
System.out.println("main`s x(local variable) = " + x);
// System.out.println("InnerA`s x = " + InnerA.x);
System.out.println("InnerA`s y = " + InnerA.y);
}
/**
* Local inner class.
*/
class InnerA {
int y = 10;
/*
* java.lang.StackOverflowError coming over here... I don`t
* understand why?
*/
// int x=new InnerClassConcepts().new InnerA().new InnerB().x;//Line-29
/**
* Inner class inside an another Inner class.
*/
class InnerB {
private int x = 22;
int z = InnerA.this.y;
}
}
}
Output_
InnerClassConcepts's x = 11
InnerB's x = 22
main's x(local variable) = 22
InnerA's y = 10
我很奇怪,爲什麼StackOverflowError
上line-29
到來時,我去掉線29 。在main
方法中工作的地方。
有人可以幫助我,我錯了什麼或背後有什麼概念?
通過方式,這給你一個機會**學習如何讀取堆棧跟蹤**。 – Ingo