下面的代码在执行时会产生堆栈溢出错误。但是,如果删除任何一个
static final GenerateStackOverflow E1 = new GenerateStackOverflow("value1");
final GenerateStackOverflow E2 = new GenerateStackOverflow("value2");
它运行时没有堆栈溢出错误。如果我有上述两行但如果只有其中一行在类中没有错误,为什么会出现堆栈溢出错误?
public class GenerateStackOverflow {
private final String value;
static final GenerateStackOverflow E1 = new GenerateStackOverflow("value1");
final GenerateStackOverflow E2 = new GenerateStackOverflow("value2");
public GenerateStackOverflow(String value) {
System.out.println("GenerateStackOverflow.GenerateStackOverflow()");
this.value = value;
}
public String getValue() {
return value;
}
public static void main(String[] args) {
GenerateStackOverflow.class.getName();
}
}