Why can't Java use the same approach ?

I can't say which approach will be used, but it's better-explained in Project Loom's proposal:

As adding the ability to manipulate call stacks to the JVM will undoubtedly be required, it is also the goal of this project to add an even lighter-weight construct that will allow unwinding the stack to some point and then invoke a method with given arguments (basically, a generalization of efficient tail-calls). We will call that feature unwind-and-invoke, or UAI. It is not the goal of this project to add an automatic tail-call optimization to the JVM.

As far as I've heard, work has not yet begun on tail calls, as Fibers and Continuations seem to currently be a higher priority.

Answer from Jacob G. on Stack Overflow
🌐
Hacker News
news.ycombinator.com › item
Tail Call Recursion in Java with ASM (2023) | Hacker News
April 1, 2025 - in the same way that passing parameters to a subfunction "creates" a special set of local variables for the subfunction, the tail recursion semantic updates this set of local variables in an especially clean way for loop semantics, allowing "simultaneous assignment" from old values to new ones ...
Discussions

Tail Call Recursion in Java with ASM
61 votes, 36 comments. One kind of optimization offered by some compilers is tail call optimization. This optimization does not bring much, since the… More on reddit.com
🌐 r/java
36
61
March 20, 2023
compiler - Why doesn't Java have optimization for tail-recursion at all? - Software Engineering Stack Exchange
From what I have read: The reason is because it is not easy to determine which method will actually be called as we have inheritance. However, why doesn't Java at least have tail-recursion optimiz... More on softwareengineering.stackexchange.com
🌐 softwareengineering.stackexchange.com
February 4, 2015
Is this tail recursion? - Question - Scala Users
I am trying to understand tail recursion. Is this an example of a tail recursive function? def fib(n: Int): Int = { var count = 2 @annotation.tailrec def go(a: Int, b: Int): Int = { count += 1 val c = a + b if (n==0) 0 if (n==1) 1 if (count==n) c else go(b, c) } go(0, 1) } More on users.scala-lang.org
🌐 users.scala-lang.org
0
January 8, 2019
Does Java support tail recursion? - Stack Overflow
Possible Duplicate: Why does the JVM still not support tail-call optimization? I see so many different answers online, so I thought I'd ask the experts. More on stackoverflow.com
🌐 stackoverflow.com
🌐
GeeksforGeeks
geeksforgeeks.org › dsa › tail-recursion
Tail Recursion - GeeksforGeeks
Tail recursion is defined as a recursive function in which the recursive call is the last statement that is executed by the function.
Published: January 20, 2026
🌐
Reddit
reddit.com › r/java › tail call recursion in java with asm
r/java on Reddit: Tail Call Recursion in Java with ASM
March 20, 2023 - And if you're debugging the recursive method to find out where in the recursion you've messed up, that's important information that's more helpful than a blanket "well at the end of the recursion, you've got the wrong thing" data point. That can be solved without too much effort I'd guess, but it is still a problem worth considering. ... The JVM itself does not support tail recursion.
🌐
JetBrains
jetbrains.com › help › inspectopedia › TailRecursion.html
Tail recursion | Inspectopedia Documentation
June 30, 2026 - Reports tail recursion, that is, when a method calls itself as its last action before returning.
Top answer
1 of 5
147

As explained by Brian Goetz (Java Language Architect at Oracle) in this video:

in jdk classes [...] there are a number of security sensitive methods that rely on counting stack frames between jdk library code and calling code to figure out who's calling them.

Anything that changed the number of frames on the stack would break this and would cause an error. He admits this was a stupid reason, and so the JDK developers have since replaced this mechanism.

He further then mentions that it's not a priority, but that tail recursion

will eventually get done.

N.B. This applies to HotSpot and the OpenJDK, other VMs may vary.

2 of 5
26

Java doesn't have tail call optimization for the same reason most imperative languages don't have it. Imperative loops are the preferred style of the language, and the programmer can replace tail recursion with imperative loops. The complexity isn't worth it for a feature whose use is discouraged as a matter of style.

This thing where programmers want to sometimes write in a FP-style in otherwise imperative languages only came into vogue in the last 10 years or so, after computers started scaling in cores instead of GHz. Even now, it's not that popular. If I suggested replacing an imperative loop with tail recursion at work, half the code reviewers would laugh and the other half would give a confused look. Even in functional programming, you generally avoid tail recursion unless other constructs like higher-order functions don't fit cleanly.

Find elsewhere
🌐
Eric Normand
ericnormand.me › podcast › what-is-tail-recursion
What is tail recursion?
If A calls B, and B called C in tail position, you don't remove that frame. If C calls itself three times, then the third time, you start reusing that last one. Then you can show the stack trace. All the ones that were just calling once are still there. You also get the benefit of the recursion not taking up infinite space. Java also does not have tail call removal.
🌐
Coderanch
coderanch.com › t › 621233 › paradigms › Java-optimise-stack-usage-tail
Does Java optimise stack usage for tail recursion (Functional programming forum at Coderanch)
Tim, This post from last year says that Java doesn't optimize tail recursion. However, Scala does and it runs on a JVM. It "changes" the code a bit to avoid the problem.
🌐
Runestone Academy
runestone.academy › ns › books › published › javajavajava › objectorienteddesign-tail-recursion.html
OBJECT-ORIENTED DESIGN: Tail Recursion
A method is tail recursive if all of its recursive calls occur as the last action performed in the method. You have to be a bit careful about this definition. The recursive call in a tail-recursive method has to be the last executed statement.
🌐
W3Schools
w3schools.com › java › java_recursion.asp
Java Recursion
Infinite recursion is when the method never stops calling itself. Every recursive method should have a halting condition, which is the condition where the method stops calling itself.
🌐
DEV Community
dev.to › paulike › tail-recursion-37o0
Tail Recursion - DEV Community
July 2, 2024 - A recursive method is said to be tail recursive if there are no pending operations to be performed on return from a recursive call, as illustrated in Figure below (a). However, method B in Figure below (b) is not tail recursive because there ...
🌐
Scala Users
users.scala-lang.org › question
Is this tail recursion? - Question - Scala Users
January 8, 2019 - I am trying to understand tail recursion. Is this an example of a tail recursive function? def fib(n: Int): Int = { var count = 2 @annotation.tailrec def go(a: Int, b: Int): Int = { count += 1 …
🌐
Softwaretechnologymq
softwaretechnologymq.github.io › recursion-tail.html
Tail recursion | Software Technology Teaching Material, Macquarie University
P.S. Java still doesn’t support tail optimization… 😞 · The value for currentState in the initial call should be 1. Sample client: Now, only the current stack frame needs to be kept in the memory and the previous stack frames for the recursive function can be discarded.
🌐
Medium
medium.com › javarevisited › tail-recursion-in-java-abc24f56b56b
Tail recursion in Java
June 29, 2020 - The Scala compiler has a built-in tail recursion optimization feature, but Java’s one doesn’t.
🌐
JanBask Training
janbasktraining.com › community › java › why-is-there-no-optimization-for-java-tail-recursion
Why is there no optimization for Java tail recursion? | JanBask Training Community
October 12, 2022 - Java doesn't have optimization for Java tail recursion for the same reason most imperative languages don't have it. Imperative loops are the preferred style of the language, and the programmer can replace tail recursion with imperative loops.
🌐
Baeldung
baeldung.com › home › java › core java › recursion in java
Recursion in Java | Baeldung
January 2, 2026 - We refer to a recursive function as tail-recursion when the recursive call is the last thing that function executes.
🌐
Quora
quora.com › What-is-tail-recursion-and-how-do-you-implement-it-in-Java
What is tail recursion and how do you implement it in Java? - Quora
Answer: Tail recursion is when the result of a recursive call is immediately passed back to the caller without any additional processing. The reason this is a good idea is that, there’s now no need to store anything from the local context on the stack—because you won’t be needing it again.
🌐
LeetCode
leetcode.com › discuss › interview-question › 1990231 › optimisation-using-tail-recursion
Optimisation using Tail Recursion - Discuss - LeetCode
April 28, 2022 - Some modern compiler can detect tail recursion and perform the optimisation by converting it to iteration to improve performance. Java, python don't support tail recursion optimisation while C and C++ do.
🌐
@ankurm
ankurm.com › home › tail vs non-tail recursion in java: definitions, examples, and when it matters
Tail vs Non-Tail Recursion in Java: Definitions, Examples, and When It Matters
October 4, 2025 - Tail recursion is when a function’s recursive call is the last operation before returning, enabling tail-call elimination in languages/runtimes that support it; non-tail recursion performs additional work after the recursive call returns. In Java, tail-call optimization is not guaranteed by the JVM, so tail recursion does not reduce stack usage unless transformed to iterative code; still, converting non-tail recursion to tail style can make iterative conversion straightforward and avoid stack overflow in production.