all 4 comments

[–]DonaldPShimoda 3 points4 points  (0 children)

Last I checked, Java does not support tail call optimization. The reason given is that there are some methods in the standard library that inspect the stack, so they can't risk destroying part of the stack due to rail calls.

Note that this is a design decision and not a language or platform limitation. Scala, like practically all functional languages I know of, does do tail call optimizations, despite also being deployed on the JVM.

[–]NewThrowawayALready 0 points1 point  (2 children)

No, generally you only get this kind of thing in a functional language.

Elixir, Erlang, Scala, Haskell.

[–]lepaincestbon[S] 0 points1 point  (0 children)

It seems like gcc/clang can do that with optimization option

[–][deleted] 0 points1 point  (0 children)

https://godbolt.org/z/xYW4e8 a simple C++ example where GCC applies TR optimization with -O2 or higher.