kotlin把函数作为参数转递给另一个函数

Posted zhangphil

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了kotlin把函数作为参数转递给另一个函数相关的知识,希望对你有一定的参考价值。

kotlin把函数作为参数转递给另一个函数

fun say(s: String, foo: (String) -> Unit) 
    print("hello")
    foo(s)


fun hi(str: String) 
    println(str)


fun main(args: Array<String>) 
    say("hello", ::hi)

 

输出:

hellohello

 

以上是关于kotlin把函数作为参数转递给另一个函数的主要内容,如果未能解决你的问题,请参考以下文章