infinite loop = tail call optimization in the above code examples. Without tail call optimization, the stack would eventually get too large and throw an exception.
For further proof, using the following tweak to purposefully throw a RuntimeException so we can see the stacktrace result:
and the result:
Here, only a single call to overflowStack() is shown in the stacktrace even though it was on recursion call #10000000.
I could have sworn I had seen something like this in POJ (Plain Old
Java) in the past as well but my quick little tests couldn't confirm it.
[ July 07, 2008: Message edited by: Marc Peabody ]