官术网_书友最值得收藏!

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.

主站蜘蛛池模板: 莲花县| 二连浩特市| 蓝山县| 扎鲁特旗| 松溪县| 泰来县| 临汾市| 凉山| 青海省| 阿克苏市| 肃北| 建水县| 会同县| 泰顺县| 盘山县| 米泉市| 建瓯市| 南宁市| 延庆县| 石首市| 高雄县| 南乐县| 琼中| 焦作市| 临洮县| 静乐县| 彩票| 南城县| 平江县| 麟游县| 尼勒克县| 廊坊市| 隆林| 崇左市| 中阳县| 荆门市| 天门市| 吉隆县| 乌恰县| 沙雅县| 巴马|