1

In scala specification, there is some description about the variance and lower bound:

The variance position of the lower bound of a type declaration or type parameter is the opposite of the variance position of the type declaration or parameter.

Which is on page 44.

I can get some idea but I can't explain it clearly. Could you give me some detail explanation on it?

Freewind
  • 193,756
  • 157
  • 432
  • 708

1 Answers1

2

Basically, lower bounds must be invariant or contravariant. Compare these, which compile:

class Good1[-A, B >: A]
class Good2[-A, B >: A]

And this, which doesn't:

class Bad1[+A, B >: A]

If Bad1 was allowed, you could do:

val worse: Bad1[Any, Int] = new Bad1[Int, Int]

Which would imply that Int >: Any, which is false.

wingedsubmariner
  • 13,350
  • 1
  • 27
  • 52