2

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

mat.mont
  • 23
  • 4

1 Answers1

1

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

xjcl
  • 12,848
  • 6
  • 67
  • 89
  • OP said that they are using `Kotlin playground`. Which is the new version of `Try Kotlin`. But I suspect that this answer is correct, since the playground does the same thing. – AlexT Mar 31 '21 at 12:35