For some reason, I can't figure out what is going ...
# announcements
r
For some reason, I can't figure out what is going on here:
Copy code
class Ref<K: Comparable<K>, T>(val key: K, val value: T) : Comparable<Ref<K, T>> {
    override fun compareTo(other: Ref<K, T>) = key.compareTo(other.key)
}

fun main(args: Array<String>) {
    val list = mutableListOf<Ref<Int, *>>()
    list.sorted()  // ERROR: Ref<Int, *> is not a subtype of Comparable<Ref<Int, *>>
}
Any ideas?
i
Try declaring
Ref
as
Copy code
class Ref<K: Comparable<K>, T>(val key: K, val value: T) : Comparable<Ref<K, *>> {
    override fun compareTo(other: Ref<K, *>) = key.compareTo(other.key)
}
r
Ah, that makes sense.
Yep, it works. Thanks @ilya.gorbunov!