scalacovariancecontravariancegeneric-variance

Is there a difference in scala type bound notation direction?


Is there a difference in scala type bound notation direction, as in is [B <: A] the same as [A >: B]?


Solution

  • B <: A means that B has an upper-bound of A. Which means that B can be any type from Nothing to A in the type hierarchy.

    A >: B means that A has a lower-bound of B, which means that A can be anything from B to Any in the type hierarchy.

    In general, they do not mean the same thing. Each one imposes a bound on a different type parameter. This isn't variance notation either, these are type bounds.