Java doesn't have an equivalent to Kotlin's 'suspend fun'. The CoroutineScope abstraction ('launch', 'join', 'await', etc) is also absent, at least until Structured Concurrency gets released [1] and Java gains StructuredTaskScope.
The runtime uses ExecutorService and friends to run coroutines, which are bits of CPS-transformed Kotlin code that are generated when you compile a 'suspend fun' declaration.
The way the code looks is completely different and significantly cleaner and faster to write in Kotlin. Actual performance and final functionality is likely to be same.
Not sure I agree with that. We've been using Kotlin on all new projects for the last year or so and I strongly prefer it over Java at this point. It has many language conveniences that make the code more succinct. Suspend functions also make it extremely simple to parallelize certain things without any ceremony.
I agree. I've almost exclusively been working with Kotlin (and a little Go) for the past 5 years, writing backend code. Recently our team got the responsibility to take over an other project where the repos are written in Java. The difference is clear, it's like coding with one of my arms tied to my back.
This take keeps coming up and I do not get it. Kotlin has ergonomics that Java cannot match without breaking changes that are anathema to the JCP, and Java has no answer at all for multiplatform.
I have lots of respect for Java but I still greatly prefer Kotlin.
13 comments
[ 3.9 ms ] story [ 46.3 ms ] threadThe best I can tell is that coroutines are a bit lighter weight (in terms of what state is managed) and have a bit simpler usage out-of-the-box.
But I've not used them myself so maybe I'm not seeing how big of advantage those are or perhaps there's more to it than that?
1: https://openjdk.org/jeps/462
The point (I think) was as an exercise to demonstrate it was possible to implement in 'userland' and how they did so.
I have lots of respect for Java but I still greatly prefer Kotlin.