Kotlin: how to pass a function as parameter to another?

后端 未结 10 2207
有刺的猬
有刺的猬 2020-11-28 04:54

Given function foo :

fun foo(m: String, bar: (m: String) -> Unit) {
    bar(m)
}

We can do:

foo(\"a message\", { println         


        
10条回答
  •  南方客
    南方客 (楼主)
    2020-11-28 05:27

    First-class functions are currently not supported in Kotlin. There's been debate about whether this would be a good feature to add. I personally think they should.

提交回复
热议问题