I'm studying Kotlin and I have a question about the flow execution of the language. I wrote this code into the Kotlin playground:
fun main() {
println("Hello,")
Thread.sleep(5000L)
print("World!")
}
I expected that the program prints "Hello,", then "World!" after 5 seconds (e.g. how it works in Java). However, it prints "Hello, World!" after 5 seconds and nothing before. Am I missing something? I've also tried to insert System.out.flush()
after the first print but it didn't work.
Thanks
https://try.kotlinlang.org and https://play.kotlinlang.org only display output after the whole program is done. This shouldn't happen with an "actual" Kotlin compiler / JVM runtime (e.g. in IntelliJ).