Hexa
02/22/2020, 11:01 AMError:(2, 44) Kotlin: Type parameter T is declared as 'in' but occurs in 'invariant' position in type SomeClass<String, T>
But it compiles when I remove the in
keyword like this: abstract class A<T>
? Given someMethod(item: SomeClass<String, T>)
takes T
as an input then using in
should work in this case?
abstract class A<in T> {
fun someMethod(item: SomeClass<String, T>) {
println(item)
}
}
open class SomeClass<K,V>(
override val entries: Set<Map.Entry<K, V>>,
override val keys: Set<K>,
override val size: Int,
override val values: Collection<V>
) : Map<K,V>{
override fun containsKey(key: K): Boolean {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
override fun containsValue(value: V): Boolean {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
override fun get(key: K): V? {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
override fun isEmpty(): Boolean {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
}
Kroppeb
02/22/2020, 11:13 AMRuckus
02/22/2020, 2:55 PMV
is invariant in SomeClass
. (Only SomeClass
is in the in
position, not its parameters.)Foso
02/22/2020, 3:01 PMHexa
02/22/2020, 3:22 PM