https://kotlinlang.org logo
Title
k

kv

07/23/2021, 6:28 PM
I have a
mutableListOf<Pair?>
that I want to check the contents of. I try something like this on Kotlin 1.5.21:
fun foo(value: List<Pair?>): Boolean {
        return list.contains(value)
    }
I get the following 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.
I can remove the error by modifying it to
return list.contains<Any?>(value)
but it feels like a weird work around. Anyone got insight as to the best way to approach this?
e

ephemient

07/23/2021, 6:33 PM
a
(Mutable)List<Pair?>
should never contain a
List<Pair?>
element. do you mean
containsAll
?
c

Casey Brooks

07/23/2021, 6:36 PM
The snippet infers that
list
is
List<List<Pair?>
.
.containsAll
would check that all elements of
value
are also elements of
list
, where the two are both
List<Pair?>
k

kv

07/23/2021, 6:41 PM
interesting kotlin 1.4.0 didn't flag it as a compile-time error
so android studio lets me build when 1.4.0 (with a lint warning), but when I bump to 1.5.21, it flags it as a compile-time error