我试图理解反射。我有以下代码:
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
get
为什么我在声明 lambda 时不能调用(参见错误注释)?lengthL1
和有什么区别lenghtNL1
吗?