Scala Types — Online notes…
Sep 6, 2018 · 1 min read
Assume that class Orange extends Fruit holds. If class Box[A] is declared, then A can be prefixed with + or -.
Awithout annotation is invariant, i.e.:Box[Orange]has no inheritance relationship toBox[Fruit].+Ais covariant, i.e.:Box[Orange]is a subtype ofBox[Fruit].var f: Box[Fruit] = new Box[Orange]()is allowed.-Ais contravariant, i.e.:Box[Fruit]is a subtype ofBox[Orange].var f: Box[Orange] = new Box[Fruit]()is allowed.

