[英]Stack overflow with tail recursion
Why am I getting a stack overflow exception? 为什么会出现堆栈溢出异常? Isn't this meant to be a tail recursive function?
这不是要成为尾递归函数吗?
public static int tailFact(int n, int mult) {
if(n == 0) {
return mult;
}else {
return tailFact(n-1, n*mult);
}
}
public static int factT(int n) {
return tailFact(n, 1);
}
public static void main(String[] args) {
factT(100000);
}
/*Exception in thread "main" java.lang.StackOverflowError
at test3.Test.tailFact(Test.java:13)
at test3.Test.tailFact(Test.java:13)
...
*/
Java不支持尾递归。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.