首页 > 解决方案 > Android kotlin - 为“父”函数返回 int

问题描述

这是代码

private fun like(id: Int): Int{

    val params = RequestParams()
    params.put("id", id)


    val client = AsyncHttpClient()
    client.post("https://www.ttt.com/ttt.php", params, object : JsonHttpResponseHandler()
    {
        override fun onSuccess(statusCode: Int, headers: Array<Header>?, response: JSONArray?)
        {
            return 1
        }
        override fun onFailure(statusCode: Int, headers: Array<Header>?, e: Throwable, response: JSONArray?)
        {
            return 0
        }
    })
}

如您所见,like在获得 API 响应后,我尝试为父函数返回 1 或 0,但错误是:

The integer literal does not conform to the expected type Unit

我找不到类似的问题!我怎样才能做到这一点?

标签: androidkotlin

解决方案


推荐阅读