private fun action1(onSuccess: (String) -> Unit){
val result="网络请求数据666"
onSuccess(result)
}
private fun onSuccess(str:String){
Log.d("TAG", "onSuccess: 接收参数str:$str")
}
private fun test1(){//入口,执行test1()
// action1(::onSuccess)//发起网络请求
action1 { str ->
Log.d("TAG", "onSuccess: 接收参数str:$str")
}//发起网络请求
}
kotlin函数作为参数传递(避免写回调接口)
最新推荐文章于 2024-07-13 10:14:35 发布