(Reflection) Implicit and explicit lambda declaration

I am trying to understand the reflection. I have the following code:

fun main(args: Array) {
println(lengthL1())
println(lengthL2(s))
println(lengthL1.get()) // Error
println(lengthL2.get(s)) // Error

println(lengthNL1.get())
println(lengthNL2.get(s))
println(lengthNL1())
println(lengthNL2(s))
}

val s = "1234"

val lengthL1: () -> Int = s::length
val lengthL2: (String) -> Int = String::length

val lengthNL1 = s::length
val lengthNL2 = String::length

Why can't I call get(see error message) when I declare lambda? Is there any difference between lengthL1and lenghtNL1?

+6
source share
1 answer

s::length- A reference to a property that is an object of type KProperty1 . A method is getdefined as a member of this type .

, (KFunction1). KFunction1 invoke(), lengthL1(), , get.

+4

All Articles