I have a `mutableListOf<Pair?>` that I want ...
# getting-started
k
I have a
mutableListOf<Pair?>
that I want to check the contents of. I try something like this on Kotlin 1.5.21:
Copy code
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
a
(Mutable)List<Pair?>
should never contain a
List<Pair?>
element. do you mean
containsAll
?
c
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
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