Taken from Essential Scala by Noel Welsh and Dave Gurnell
Invariant: Foo[T]
: Foo[A]
and Foo[B]
are unrelated regardless
of the relationship between A
and B
Covariant: Foo[+T]
-> Foo[A]
is a supertype ofFoo[B]
if A
is a supertype of B
.
Contravariant: Foo[-T]
-> Foo[A]
is a subtype of Foo[B]
if A
is a supertype of B
.