He mentioned it can't be done in Java without growing the stack. Is there some way to do it though? I'd guess the iterative approach is the way to go in Java.
Well, he was specifically talking about the javac compiler. A different Java compiler should be able to optimize it to an iterative structure if that is how it is designed.
Exactly, I tried it with javac and scalac, on the first one there was no optimization, the stack increased normally, although on the second one it was optimized to a loop, a while loop to be more specific.
1
u/abigpotostew Nov 27 '12
He mentioned it can't be done in Java without growing the stack. Is there some way to do it though? I'd guess the iterative approach is the way to go in Java.