- 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.
推薦閱讀
- Java程序設計(慕課版)
- Ceph Cookbook
- 摩登創客:與智能手機和平板電腦共舞
- Vue.js 2 and Bootstrap 4 Web Development
- SQL 經典實例
- Python爬蟲、數據分析與可視化:工具詳解與案例實戰
- Kivy Cookbook
- 區塊鏈項目開發指南
- Learning VMware vSphere
- JavaScript前端開發基礎教程
- PostgreSQL 12 High Availability Cookbook
- Python全棧開發:數據分析
- 詩意的邊緣
- Cloud Development andDeployment with CloudBees
- C語言解惑:指針、數組、函數和多文件編程