Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Kotlin: Type inference failed. The value of the type parameter T should be mentioned in input types

I’m new to Kotlin, for the piece of the below code:

fun a(stcd: String) {
        val res = mutableSetOf<String>()
        val aaa = mutableListOf<Map<String, Set<String>>>()
        aaa.stream().filter { x: Map<String, Set<String>> -> x.isNotEmpty() }
            .filter { x: Map<String, Set<String>> ->
                x.values.contains(stcd) // throws error
            }.forEach { x: Map<String, Set<String>> ->
                x.forEach { (k: String, v: Set<String>?) ->
                    res.add(k)
                }
            }
    }

Could anyone point out why contains throws error:Type inference failed. The value of the type parameter T should be mentioned in input types (argument types, receiver type or expected type). Try to specify it explicitly.?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

This is because x.values is not a Set<String>, as you probably think it is. In fact, it’s aCollection<Set<String>> as per the definition of values. So, such a collection can’t contain a String type.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading