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

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.

主站蜘蛛池模板: 万山特区| 新丰县| 东丽区| 依兰县| 庆安县| 兴山县| 阳江市| 铜陵市| 定襄县| 乐至县| 慈利县| 吉安县| 肇源县| 榆中县| 禹城市| 新竹市| 宁津县| 图木舒克市| 南部县| 虹口区| 都江堰市| 台前县| 连城县| 涪陵区| 尉犁县| 福州市| 胶州市| 太康县| 毕节市| 墨江| 前郭尔| 屯门区| 土默特右旗| 海原县| 军事| 北宁市| 彩票| 海林市| 冀州市| 合阳县| 广河县|