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

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.

主站蜘蛛池模板: 北川| 云安县| 平罗县| 项城市| 永顺县| 永修县| 巴南区| 潜江市| 红原县| 新巴尔虎左旗| 日喀则市| 巫山县| 稷山县| 会宁县| 黑龙江省| 江山市| 任丘市| 阿拉尔市| 雷山县| 钦州市| 呼图壁县| 汉源县| 措美县| 丽水市| 孟津县| 基隆市| 苗栗县| 时尚| 封开县| 包头市| 寿宁县| 商河县| 崇义县| 济南市| 永川市| 叙永县| 金秀| 景东| 甘肃省| 岳池县| 西青区|