Variance In Scala
1. All values have a type
2. Types have supertype relationships up to Any
3. Types have subtype relationships down to Nothing
4. References can store subclass instances (polymorphism)
Variance example: List[T]
In general, there are three modes of variance:
To understand Variance, we must consider the container and the content.
Polymorphism: We can store the child class in the parent class reference.
Considering the following relation let's understand variance:
Example 1: In-Variance
Example 2: Co-Variance
Example 3: Contra-Variance