Tag: 函数调用

接口与函数调用的Kotlin性能

在Kotlin中,因为我们可以使用函数作为变量,所以我倾向于用这样的函数调用替换接口: 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 { […]