Kotlin docs表示它支持高阶函数.::function当将顶级函数作为参数传递时,为什么语言甚至需要语法?
鉴于:
fun isOdd(x: Int) = x % 2 != 0
val numbers = listOf(1, 2, 3)
println(numbers.filter(::isOdd)) // here.
Run Code Online (Sandbox Code Playgroud)
为什么不呢
fun isOdd(x: Int) = x % 2 != 0
val numbers = listOf(1, 2, 3)
println(numbers.filter(isOdd)) // simple and makes more sense
Run Code Online (Sandbox Code Playgroud)
更多关于函数引用语法的信息.
kotlin ×1