美文网首页
用Kotlin实现简单的登录功能

用Kotlin实现简单的登录功能

作者: GoLearning轻松学 | 来源:发表于2022-01-10 09:50 被阅读0次

    用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)
        }
    }
    

    相关文章

      网友评论

          本文标题:用Kotlin实现简单的登录功能

          本文链接:https://www.haomeiwen.com/subject/zkkmcrtx.html