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

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.

主站蜘蛛池模板: 故城县| 霞浦县| 洛川县| 清新县| 敦化市| 云南省| 龙岩市| 老河口市| 和平区| 宁蒗| 凤山市| 五莲县| 南京市| 乌拉特中旗| 龙里县| 全南县| 思茅市| 安义县| 红原县| 丽水市| 甘孜县| 资溪县| 钦州市| 桃园县| 湖州市| 德昌县| 连州市| 普定县| 嘉义市| 西宁市| 玉树县| 平塘县| 长宁县| 定结县| 邵阳县| 莱阳市| 泊头市| 织金县| 大英县| 巴彦淖尔市| 德格县|