2 ms·
Interesting, does it depend on Kotlin compiler or it can be implemented in Java as well?
by deepsun 2y ago
Interesting, does it depend on Kotlin compiler or it can be implemented in Java as well?
- gavinray 2y agoThe "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-inspection https://github.com/andreisilviudragnea/remove-recursion-insp...