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:
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...