美文网首页
kotlin 高阶函数极简用法

kotlin 高阶函数极简用法

作者: 忧郁的老王 | 来源:发表于2021-02-20 16:44 被阅读0次
  • 插播一段高阶函数用法
    1.定义函数A
    2.定义函数B在B的参数表中嵌入和A一致的参数形式和返回值形式
    3.调用函数B并将A作为B的一个参数引入,引入方式为::A
    如下
 fun runTest() {
        caculate(1,1,::high_level)
    }

    fun caculate(a: Int, b: Int, operate: (a: Int, b: Int) -> Int) {
        var result = operate(a, b)
        print("the result is " + result)
    }

    fun high_level(a: Int, b: Int):Int {
        return a + b
    }

相关文章

网友评论

      本文标题:kotlin 高阶函数极简用法

      本文链接:https://www.haomeiwen.com/subject/cohxfltx.html