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

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.

主站蜘蛛池模板: 昭觉县| 屯门区| 宁国市| 右玉县| 栾川县| 高要市| 金川县| 大理市| 陵川县| 手机| 浑源县| 昔阳县| 云龙县| 从化市| 汝阳县| 黄梅县| 田东县| 神木县| 同江市| 大埔区| 海南省| 登封市| 得荣县| 肇州县| 社旗县| 曲松县| 哈尔滨市| 甘南县| 翁源县| 普兰县| 双辽市| 老河口市| 孟连| 无为县| 恩平市| 揭西县| 陇南市| 太谷县| 白城市| 浙江省| 呼玛县|