Kotlin 高阶函数详解 - 知乎 (zhihu.com)
Kotlin inline noinline crossinline 解答 - 掘金 (juejin.cn)
调用代码
fun main() {
println("===================oneParam")
fun_oneParam(){
println("3")
println(wxId)
}
println("===================twoParam")
fun_twoParam(listener = {name, isMan ->
println("name="+name +" ;isMan="+isMan)
})
}
fun fun_oneParam(block:UserAvatar22.()->Unit){//只有一个参数
println("===1")
block.invoke(UserAvatar22("id","avatar"))
println("===2")
}
fun fun_twoParam(listener:(name: String,isMan:Boolean)->Unit){//2个参数
println("1----fun_twoParam")
listener.invoke("name",false)
println("2----fun_twoParam")
}
data class UserAvatar22(val wxId: String,val avatar: String)
运行结果
===================oneParam
===1
3
id
===2
===================twoParam
1----fun_twoParam
name=name ;isMan=false
2----fun_twoParam