Why the code print "Hello World"

Hi all, I am learning Kotlin with Samples. With the code following:

fun run() {

    val run: () -> Unit = {
        println("Run run run!")
    }

    // 新增一个 run 函数
    fun run() = println("Hello World")

    object : Runnable {
        override fun run() = run()
    }.run()
}

fun main(args: Array<String>) {
    run()
}

Why the console print “Hello World” not “Run run run!” . Thanks!

Hi!

You can see an explanation here:

language design - How resolving Kotlin functions/properties with the same name work? - Stack Overflow.

3 Likes

Thank you very much. I Got it.