1 、Kotlin之函数作为参数传递
我们在写BaseQuickAdapter适配器的时候,有时候嵌套多个BaseQuickAdapter,如果最里面的view触发点击事件,我们可以把函数作为参数通过构造函数一层一层传递进去。
2、代码测试
private var test: (Boolean, Int, Int) -> Unit = {result, a, b ->
Log.i(TAG, "rseult is:" + result)
Log.i(TAG, "a is:" + a)
Log.i(TAG, "b is:" + b)
test1(result, a, b)
}
private var test1: (Boolean, Int, Int) -> Unit = { result1, a1, b1 ->
Log.i(TAG, "rseult1 is:" + result1)
Log.i(TAG, "a1 is:" + a1)
Log.i(TAG, "b1 is:" + b1)
}
class A(var result: Boolean, var a: Int, var b: Int, var test1: (Boolean, Int, Int) -> Unit) {
fun testA() {
test1(result, a, b)
}
}
fun dodo() {
var a = A(true, 1, 2, test)
a.testA()
}