Is there a difference in scala type bound notation direction?

104 Views Asked by At

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

2

There are 2 best solutions below

1
On BEST ANSWER

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.

0
On

Here [B <: A] you declare type B which extends A, here [A >: B] you declare type A which is a parent of type B.