DEV Community

Discussion on: Kotlin is so nice – it prevents bugs πŸ› before you add them…

Collapse
 
androiddeveloperlb profile image
AndroidDeveloperLB • Edited

About the Thread.start issue, I think you went too far. Kotlin coroutines are very different from Thread, and I'm not sure they are as much part of the language anyway...

If you want something more similar, it should have been.... "thread" .

You use it this way:

thread{
//do something in the newly created thread.
}
Enter fullscreen mode Exit fullscreen mode

That's it.

Collapse
 
mreichelt profile image
Marc Reichelt

You're right, Kotlin Coroutines are very different from Java Threads. For example, one can write a Coroutine that runs on the same main thread as the regular code (and doesn't use any other threads at all).
My point here was: Coroutines are quite becoming the default to do concurrency operations in Kotlin (especially since Java threads are not available on all platforms), and they fix things that have not been addressed before. Like the aforementioned example of calling a suspend function, but forgetting to handle it correctly.

I think your example is a really good one to show again how Kotlin makes existing Java-APIs easier to handle, and code easier to write, and fewer possible bugs. πŸ‘
I'll link to your comment in the article! πŸ™‚