There are a couple of differences to watch out for. For example:
Copy code
var string: String = "a"
val f1: () -> Int = { string.length }
val f2: () -> Int = string::length
println(f1()) // 1
println(f2()) // 1
string = "aaa"
println(f1()) // 3
println(f2()) // 1
👍 2
w
wasyl
12/05/2019, 2:55 PM
That’s right, I also got a NPE once because the receiver wasn’t yet initialized, too. So it does change something, but function reference still creates the same lambda as writing it manually?