基础的高阶函数使用方法:
fun testFunction(value1: Int, func: (Boolean) -> Unit) {
func.invoke(value1 == 1)
}
如何让传入的函数可空呢
fun testFunction(value1: Int, func: ((Boolean) -> Unit)?) {
func?.invoke(value1 == 1)
}
或者这样
fun testFunction(value1: Int, func: ((Boolean) -> Unit)? = null) {
func?.invoke(value1 == 1)
}
316



被折叠的 条评论
为什么被折叠?



