angryziber / kotlin-puzzlers

A collection of Kotlin Puzzlers
419 stars 58 forks source link

New puzzler #59

Closed rpuxa closed 4 years ago

rpuxa commented 4 years ago
    fun Any.toConsole(): Unit = print("$this  ")

    fun main() {
        val list = listOf(1, 2, 3)
        val array = IntArray(1)

        { 42 }.toConsole()
        list.toConsole()
        array.toConsole()
    }

1) [I@3f99bd52 [1, 2, 3] kotlin.Unit 2) 42 java.util.ArrayList@4481f34a [I@448139f0 3) kotlin.Unit [1, 2, 3] [I@448139f0 4) Function0 java.util.ArrayList@4481f34a [I@448139f0 5) Function0 [1, 2, 3] [I@448139f0

Correct answer: first. Because { 42 } its a second argument of IntArray constructor

SerVB commented 4 years ago

Great catch! I love it. Could you also provide Kotlin version?

rpuxa commented 4 years ago

Great catch! I love it. Could you also provide Kotlin version?

What do you mean?

SerVB commented 4 years ago

Is this 1.3.40?

rpuxa commented 4 years ago

Is this 1.3.40?

It works at 1.3.40 and 1.3.41 versions. I've tried