This means that tail - recursive methods in the java language can result in unexpectedly large memory usage 这就意味着在java语言中采用尾递归方法将导致巨大的内存占用,而这并不是我们期望的结果。
My next installment of diagnosing java code will examine how tail - recursive methods can impact performace of your java programs 诊断java代码的下一部分将考查尾递归方法如何影响java程序的性能。
But because the variable parameter values are sent to the recursive call all at once , it is much easier to get the updated values right than it is in a loop 但因为所有可变的参数值都一次传给了递归调用,所以比起循环来,在尾递归中可以更容易地得到更新值。
Although the manual is , of course , written for common lisp , the discussion on tail recursion is applicable to other languages , including the java language 虽然这本手册是(当然是)为common lisp写的,但其中关于尾递归的讨论也适用于其他语言,包括java语言。
But although it is well known how to automatically transform a tail - recursive function into a simple loop , the java specification doesn t require that this transformation be made 但是,尽管大家都熟知如何把一个尾递归函数自动转换成一个简单循环, java规范却不要求做这种转换。
So , as the example in listing 3 shows , we cannot expect static compilers to perform transformation of tail recursion on java code while preserving the semantics of the language 因此,如清单3中的示例所示,我们不能期望静态编译器会在保持语言语义的同时对java代码执行尾递归转换。
The solution is relatively simple : because these tail - recursive functions are really just easier ways of writing loops , have the compiler automatically transform them to loops 解决方案比较简单:因为尾递归函数实际上只是编写循环的一种更简单的方式,所以就让编译器把它们自动转换成循环形式。
Therefore , to guarantee reasonable performance across jvms , you should always try to write code that most naturally fits a tail - recursive pattern in an iterative style instead 因此,为了保证您的程序在所有jvm上都有适当的性能,您应始终努力把那些最自然地符合尾递归模式的代码按迭代风格编写。
Because of this attribute , there is a nice correspondence between tail - recursive functions and loops : each recursive call can be thought of simply as one more iteration through a loop 由于这一特点,在尾递归函数和循环之间有一个很好的对应关系:可以简单地把每个递归调用看作是一个循环的多次迭代。
He shows why this matters and offers a bit of code to help you determine whether your just - in - time compiler can transform tail recursion on code while preserving semantics 他说明了为什么这是一个重要问题,并提供了一段代码来帮助判断您的即时( jit )编译器是否会在保持语言语义的同时做尾递归代码转换。