类A有一个参数name,现在把name 通过接口回调的方式传出去,设置一个延迟加载的方法参数,再类B中实例化方法,就能进行接口回调
class A {
private val name = "kotlin"
lateinit var function: (name: String) -> Unit
fun doSomething() {
function(name)
}
}
B类如下:
class B {
var name_in_a = ""
init {
val a = A()
a.function = { name ->
name_in_a = name
}
}
}