why the star projection is required in an is check in kotlin

50 views Asked by At

I have this code


class Dog<T: Comparable<T>>(private val name: Str, private val weight: T): Comparable<Dog<T>> {
 override fun compareTo(other: Dog<T>): Int {
  return weight.compareTo(other.weight)
 }

 override fun equals(other: Any?): Boolean {
  if (other == null || other !is Dog<*>) return false
  return name == other.name && weight == other.weight
 }
}

* means Any? but * is accepted and Any? is not. Why is that?

0

There are 0 answers