kotlin如何在多层应用功能中引用外部作用域 [英] kotlin how to refer outer-scope this in multi-layer apply functions

查看:413
本文介绍了kotlin如何在多层应用功能中引用外部作用域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如:

 v1?.apply {
       v2?.apply {
           call(this, target, outerThis);
       }
    }

我的问题是如何指代"outerThis"? 谢谢您的帮助.

my question is how to refer to "outerThis"? thanks for any help.

推荐答案

您可以使用限定this 表达式:

You can use a label and then a qualified this expression:

v1?.apply outer@ {
    v2?.apply {
        call(this, target, this@outer)
    }
}

这篇关于kotlin如何在多层应用功能中引用外部作用域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆