This 表达式

    • 在的成员中,this 指的是该类的当前对象。
    • 扩展函数或者中, this 表示在点左侧传递的 接收者 参数。

    Implicit this

    1. fun main() {
    2. class A {
    3. fun printLine() { println("Member function") }
    4. fun invokePrintLine(omitThis: Boolean = false) {
    5. }
    6. }
    7. A().invokePrintLine() // Member function
    8. A().invokePrintLine(omitThis = true) // Top-level function