This 表达式
为了记录下当前接受者,我们使用 this 表达式:
在类的成员中,this 表示当前类的对象
如果 this 没有应用者,则指向的是最内层的闭合范围。为了在其它范围中返回 this ,需要使用标签
this使用范围
为了在范围外部(一个类,或者表达式函数,或者带标签的扩展字面函数)访问 this ,我们需要在使用 this@lable 作为 lable
class A { // implicit label @Ainner class B { // implicit label @Bfun Int.foo() { // implicit label @fooval a = this@A // A's thisval b = this@B // B's thisval c = this // foo()'s receiver, an Intval c1 = this@foo // foo()'s receiver, an Intval funLit = @lambda {String.() ->val d = this // funLit's receiverval d1 = this@lambda // funLit's receiver}val funLit2 = { (s: String) ->// foo()'s receiver, since enclosing function literal// doesn't have any receiverval d1 = this}}}}
