Kotlin具名函数和匿名函数

Kotlin具名函数和匿名函数


inline  fun showpersonInfo(name: String ,age: Int , sex:Char , study: String , showInfo:(String) -> Unit){
    val showResl = "$name + $age + $sex + $study"
    showInfo(showResl)
}

fun  showInfo(reslut:String) {
    println("swift: $reslut")
}






fun show(info: String): (String , Int) -> String{
    println("info: $info")
    return { neme: String, age: Int ->
        "hello+ $age"
    }
}


private  inline fun loginAPI(userName:String, passWord: String, apiResponse: (String,Int) -> Unit) {

    if (userName == "12346" && passWord == "QQ1234"){

        apiResponse("登录成功", 200)
    }else{
        apiResponse("登录失败", 404)
    }

}



private  fun reposnerFun(message: String , code: Int) {
    println("服务器返回结果= message:$message , code: $code")

具体调用


 //匿名函数
    showpersonInfo("jack",12,'男',"swift") {  println("eror: $it") }
    //具名函数
    showpersonInfo("ROSE",35,'女',"历史",:: showInfo)


你可能感兴趣的:(Kotlin具名函数和匿名函数)