相关疑难解决方法(0)

为什么Kotlin需要函数引用语法?

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

10
推荐指数
2
解决办法
1932
查看次数

标签 统计

kotlin ×1