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

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.

主站蜘蛛池模板: 阳东县| 延吉市| 武城县| 讷河市| 临清市| 武邑县| 万盛区| 高州市| 阳原县| 青岛市| 图片| 平果县| 万荣县| 资兴市| 拜城县| 宜黄县| 巧家县| 从江县| 新河县| 扎兰屯市| 蕲春县| 黄冈市| 开化县| 茌平县| 托克托县| 大洼县| 锡林郭勒盟| 宣威市| 类乌齐县| 盐津县| 宝丰县| 临泉县| 思茅市| 鲁山县| 玛曲县| 揭阳市| 双辽市| 阳新县| 德清县| 报价| 徐闻县|