用Kotlin实现简单的登录功能,使用了高阶函数
fun main(args: Array<String>) {
loginAction("用户A", "123456") {
if (it) println("登录成功") else println("登录失败")
}
}
fun loginAction(userName: String, userPsw: String, loginResponseResult: (Boolean) -> Unit) {
if (userName == null && userName == null)
return
else
loginEngine(userName, userPsw, loginResponseResult)
}
private fun loginEngine(userName: String, userPsw: String, loginResponseResult: (Boolean) -> Unit) {
if ("用户A".equals(userName) && "123456".equals(userPsw)) {
loginResponseResult(true)
} else {
loginResponseResult(false)
}
}
网友评论