News for hackers. Stuff that matters.
Re:Tail Call Recursion in Java with ASM (2023) by gavinray on Sunday March 30, 2025 @03:29PM (#43526815)
The "DeepRecursiveFunction<T,R>" could be implemented in Java. The Kotlin implementation leverages Kotlin's native coroutines and uses continuations.

It'd require a bit of engineering to get something working in native Java I'd imagine, even with the new JDK Structured Concurrency API offering you a coroutines alternative.

On the other hand, "tailrec" is a keyword and implemented as a compiler optimization.

The closest I've seen in Java is a neat IntelliJ plugin that has a transformation to convert recursive method calls into imperative loops with a stack frame.

This transformation and resulting tool was the result of someone's thesis, it's pretty cool:

https://github.com/andreisilviudragnea/remove-recursion-insp...

There are no comments on this comment yet.