I remember that you should always avoid using recursive method calls in Java . I thought the reason was that the overhead incurred while saving the invoked methods on the heap was not worth the shortened lines of code in the implementation.
However, recently I was told that this is not true if the recursive implementation fixes the problem space pretty well. I did not understand this completely, since each recursive method can be implemented iteratively , for example, using the stack.
There are several problems that can be solved using recursive implementations, for example, through the tree data structure.
Is it always to avoid recursive implementations in Java or not ? If not, what is a good criterion for deciding whether to use a recursive or iterative implementation. In any case, is the overhead generated important or optimized? I read about stackoverflow that recursive optimization is not supported in Java.
source share