首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

java 变量初始化 简单犯错

2012-12-21 
java 变量初始化 容易犯错private static TBase t new TBase(1)//private TBase tt new TBase(tt

java 变量初始化 容易犯错
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。

原因、初始化静态变量对象 时 先初始化对象的成员变量,递归操作导致溢出。

热点排行