- Learn Kotlin Programming(Second Edition)
- Stephen Samuel Stefan Bocutiu
- 123字
- 2021-06-24 14:13:28
This expression
When inside a class or function, we often want to refer to the enclosing instance. For example, an instance may want to invoke a method passing itself as an argument. To do this, we use the this keyword:
class Person(name: String) { fun printMe() = println(this) }
In Kotlin terminology, the reference referred to by the this keyword is called the current receiver. This is because it was the instance that received the invocation of the function. For example, if we have a string and invoke the length, the string instance is the receiver.
In members of a class, this refers to the class instance. In extension functions, this refers to the instance that the extension function was applied to.
推薦閱讀
- Instant Node Package Manager
- iOS 9 Game Development Essentials
- PHP 7底層設計與源碼實現
- FFmpeg入門詳解:音視頻流媒體播放器原理及應用
- Microsoft System Center Orchestrator 2012 R2 Essentials
- Jupyter數據科學實戰
- Arduino家居安全系統構建實戰
- Learning Concurrent Programming in Scala
- Scala Reactive Programming
- C/C++程序員面試指南
- 用戶體驗可視化指南
- Canvas Cookbook
- 計算機應用基礎項目化教程
- QPanda量子計算編程
- Android移動應用開發項目教程