private static TBase t = new TBase("1");
//private TBase tt = new TBase("tt");
public TBase(String str){
System.out.println(str);
}
private TBase bb = new TBase("cc");
public static void main(String[] args) {
//TBase t = new TBase("0");
System.out.println("hello");
}
}
这个类运行 就会出现;java.lang.StackOverflowError。
原因、初始化静态变量对象 时 先初始化对象的成员变量,递归操作导致溢出。
//private TBase tt = new TBase("tt");
public TBase(String str){
System.out.println(str);
}
private TBase bb = new TBase("cc");
public static void main(String[] args) {
//TBase t = new TBase("0");
System.out.println("hello");
}
}
这个类运行 就会出现;java.lang.StackOverflowError。
原因、初始化静态变量对象 时 先初始化对象的成员变量,递归操作导致溢出。