在 Kotlin 中,我们已经知道关键字 this 指的是我们正在操作的当前对象。
在本文中,我们将讨论与 this 使用相关的两个概念,即隐式 this 和显式 this。
2. 接收者
this 的接收者是使用 this 时的上下文对象。当我们在 Kotlin 中的函数或方法中使用 this 时,我们指的是对象本身或接收动作的对象:
class Outer {
fun checkThis() {
val b = this
// 其他代码...
}
}
大约 4 分钟