简体   繁体   中英

Type inference failed. the value of the type parameter t should be mentioned in input types

I am beginner at kotlin and I am trying to filter items which are present in one list, however i am using a loop and iterator for this purpose. I am getting mentioned exception in the if condition in here. Can some one guide me where i am wrong. I am pasting my function here.

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

        })

    }

This is because

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

You have to get a string value of each gateway in the list. You can do it with asString method of JsonObject :

if (e.get("value").asString in response!!) {
    gateways.remove(e)
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM