//函数类型作为函数的返回类型
fun main(args: Array<String>) {
val result = showAction()
println(result)
/*----------------------------------------------------*/
// r是show函数的返回值
val r = show("Kotlin语言")
//nimingShowMethod 是 showMethod函数的返回值,这个返回值是一个函数
val nimingShowMethod = showMethod("Kotlin语言")
//nimingShowMethod是匿名函数
println(nimingShowMethod("yuknight", 25))
}
/*----------------------------------------------------*/
private fun showAction(): (Int, Double) -> String {
val name = "yuknight"
return { age: Int, weight: Double ->
val thisInfo = "(今年是2022年)"
"我的名字是:$name,${thisInfo},年龄:$age, 体重:$weight"
}
}
/*----------------------------------------------------*/
fun show(info:String):Boolean{
println("我是show函数 info:$info")
return true
}
//showMethod函数 返回一个匿名函数
fun showMethod(info:String):(String, Int)->String{
println("我是showMethod函数 info:$info")
//返回一个匿名函数
return { name:String, age:Int ->
"我就是匿名函数:我的name:$name,age:$age"
}
}
Function type in Kotlin as return type of function
Guess you like
Origin blog.csdn.net/liujun3512159/article/details/130003472
Ranking