【发布时间】:2019-12-12 18:08:47
【问题描述】:
当我有两个类(A 和 B)并且 A 有一个名为 myFunA 的函数然后调用 myFunB(在 B 类内部)时,myFunB 中的代码是否有可能获得对 A 类的引用,该引用用于打电话给myFunB?我总是可以将引用作为参数传递,但我想知道 Kotlin 是否有办法允许函数确定父调用者的实例。
class A {
fun myFunA() {
val b = B()
b.myFunB() {
}
}
}
class B {
fun myFunB() {
// Is it possible to obtain a reference to the instance of class A that is calling
// this function?
}
}
【问题讨论】:
-
不,我不相信。
标签: kotlin