java – 我在这段代码上得到了一个StackOverFlowException,因为我的JVM不支持尾调用优化,对吧?

前端之家收集整理的这篇文章主要介绍了java – 我在这段代码上得到了一个StackOverFlowException,因为我的JVM不支持尾调用优化,对吧?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我在这个Java方法上得到了一个StackOverflowException:

private static final Integer[] populate(final Integer[] array,final int length,final int current) {

    if (current == length) {
        return array;
    } else {
        array[current] = TR.random.nextInt();
        System.out.println(array[current]);
        return populate(array,length,current + 1);
    }
}

我正在玩尾调用递归,所以我猜这是当JVM没有将堆栈短路时会发生什么?

最佳答案
我所知道的没有JVM支持调用优化.这不是疏忽.显然,这种优化对Java反射和Java安全管理器有重大影响.

参考文献:

> “Tail calls in the VM” by John Rose @ Oracle.
> Bug 4726340 – RFE: Tail Call Optimization

猜你在找的JVM相关文章