【发布时间】:2018-07-30 09:44:49
【问题描述】:
我的问题和Java: calling outer class method in anonymous inner class 差不多。 但这次我们使用的是 Kotlin。
如下例,我想在对象表达式中调用funB(),但我只失败了两次。
class A {
lateinit var funA: () -> Unit
lateinit var funB: () -> Unit
fun funC() {
var b = object : B() {
override fun funB() {
funA() // A.funA()
// Two attempts to fail
funB() // b.funB(), not my expect
A::funB() // compile error
}
}
}
}
感谢您的回答!
【问题讨论】:
-
this@A.funB() -
@yole 这就是答案 ;)
标签: kotlin