https://kotlinlang.org logo
#getting-started
Title
# getting-started
h

hadal

11/10/2016, 11:18 PM
Hi guys! Could anyone explain me, how does this code works? Thanks in advance.
Copy code
data class User(val firstName: String, var lastName: String)

fun <K> KProperty<K>.test(value: K) {}
fun <K> KMutableProperty<K>.test2(value: K) {}

fun main(args: Array<String>) {
    User::firstName.test("test")
    User::firstName.test(42) // Works as well. Why?

    User::lastName.test2("test")
    User::lastName.test2(42) // Doesn't work, as expected.
}