This Expression

    • In a member of a class, this refers to the current object of that class.
    • In an or a function literal with receiver this denotes the receiver parameter that is passed on the left-hand side of a dot.

    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