1
在科特林,我们可以使用函数作为变量,我倾向于功能来代替接口调用是这样的:科特林性能
class A {
private var listener: AA? = null
var callThis: (() -> Unit) ? = null)
fun somethingHere() {
callThis?.invoke()
listener?.callThis2()
}
fun attachListener(listener: AA) {
this.listener = listener
}
interface AA {
fun callThis2()
}
}
class B {
init {
val objectA = A()
objectA.callThis = {}
objectA.attachListener(object : A.AA {
override fun callThis2() {
}
})
}
}
因为我是很新,科特林,我会喜欢了解不同之处和我应该在哪些场景中使用函数调用vs接口,除了(明显)抽象。或者它是一样的,并且函数调用与匿名内部类完全一样
该函数被调用很多次,每次精确地调用100次,并且我想知道,就性能而言,哪个更好
你能重新格式化代码吗?在目前的状态下,它很难阅读。谢谢 – voddan