Kotlin基础教程-this关键字

xiaoxiao2021-02-28  122

this

this

this关键字可以作用到类,函数,lambda表达式

class A { // implicit label @A inner class B { // implicit label @B fun Int.foo() { // implicit label @foo val a = this@A // A's this val b = this@B // B's this val c = this // foo()'s receiver, an Int val c1 = this@foo // foo()'s receiver, an Int val funLit = @lambda {String.() -> val d = this // funLit's receiver val d1 = this@lambda // funLit's receiver } val funLit2 = { (s: String) -> // foo()'s receiver, since enclosing function literal // doesn't have any receiver val d1 = this } } } }
转载请注明原文地址: https://www.6miu.com/read-54116.html

最新回复(0)