类型推断失败。类型参数 t 的值应在输入类型中提及

ice*_*rit 11 android kotlin

我是 kotlin 的初学者,我正在尝试过滤一个列表中存在的项目,但是我为此使用了循环和迭代器。我在in这里的 if 条件中被提及异常。有人可以指导我哪里出错了。我在这里粘贴我的功能。

fun getGateWays(
        gateways: ArrayList<JsonObject>?,
        callback: ResponseCallback<ArrayList<JsonObject>, String>
    ) {


        getDistinctGateways(object : ResponseCallback<List<String>?, String>() {

            override fun onFailure(failure: String) {
            }

            override fun onSuccess(response: List<String>?) {

                for(e in gateways!!.iterator()){
                    if(e.get("value") in response){
                        gateways.remove(e)
                    }
                }
                callback.onSuccess(gateways!!)
            }

        })

    }
Run Code Online (Sandbox Code Playgroud)

And*_*ana 6

您必须获取列表中每个网关的字符串值。asString您可以使用以下方法来完成JsonObject

if (e.get("value").asString in response!!) {
    gateways.remove(e)
}
Run Code Online (Sandbox Code Playgroud)


Kis*_*rya 2

这是因为

    gateways.iterator() will give Iterator<JsonObject>
    e is of JsonObject type and response is the type List<String>
Run Code Online (Sandbox Code Playgroud)