【问题标题】:Stack overflow with tail recursion尾递归堆栈溢出
【发布时间】:2015-11-01 19:20:36
【问题描述】:

为什么会出现堆栈溢出异常?这不就是一个尾递归函数吗?

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 tail-recursion


【解决方案1】:

Java 不支持尾递归。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-03-06
    • 1970-01-01
    • 2015-04-04
    • 2017-01-20
    • 2018-12-02
    • 2017-09-06
    • 2019-07-08
    • 2015-08-05
    相关资源
    最近更新 更多