class InfiniteRecursion {
@Override
public String toString() {
return "SXD" + this;
}
}
字符串’SXD’碰到加号会试图把后面的this也转化成String,于是调用this.toString()进入死循环,抛出java.lang.StackOverflowError异常,
Java编程思想(P510)采用调用父类的方法super.toString()
来源:CSDN
作者:CodingBugs
链接:https://blog.csdn.net/qq_33061377/article/details/79249942