小编임세준*_*임세준的帖子

Kotlin(::) 中的成员引用

class Student(val id: Int, val name: String)

fun main() {
    val list = arrayListOf<Student>(Student(200, "Lim"), Student(100, "Kim"), Student(300, "Park"))

    println(list.map { Student::name })
    println(list.map { student -> student.name })
}
Run Code Online (Sandbox Code Playgroud)

结果:

[val Student.name: kotlin.String, val Student.name: kotlin.String, val Student.name: kotlin.String]
[Lim, Kim, Park]
Run Code Online (Sandbox Code Playgroud)

我不明白为什么会这样。

kotlin

4
推荐指数
1
解决办法
935
查看次数

标签 统计

kotlin ×1