Kontlin returns anonymous function

The fascinating thing about kotlin is that it can pass functions directly. . . Benchmark java interface

But what makes him super 'charming' is that he can. . Return function. .

This is outrageous bros. . I can't even think about this java

Come on Demo

import java.util.*

fun main() {
    val test = testRetrunFun(611)
    val test1 = test("什么jb 泡沫?", 404)
    println(test1)
}

fun testRetrunFun(int: Int): (String, Int) -> String {
    return { result: String, code: Int ->
        "全都是泡沫。是美丽的花火。 我本来传入了 int: ${int} 现在的函数又传入了 result $result code:$code "
    }
}

This is already very fashionable. .

Because I have learned a lot of languages. . It's interesting to call this for the first time.

Guess you like

Origin blog.csdn.net/mp624183768/article/details/123606971