Scala | Variances (original) (raw)

Last Updated : 10 Apr, 2019

Variance is the interconnection of Sub-Typing relationships which are either of complicated types or of their constituent types. Variance explains inheritance correlation of Types that have parameters or arguments within them. These types belongs to the generic classes, which takes a type like a parameter. In the presence of Variance one can create relations between complicated types and in its absence we won't be able to reiterate the abstraction class. The Scala Variances are of three types, which are as follows:

  1. Covariant
  2. Contravariant
  3. Invariant

Some important points:

Types of Variances

Let's discuss each type in detail.

}
`
Output:
Kanchan
Rahul
Nidhi
Geeta
Here, List of boys and girls both belongs to the List of students as they are its sub-type and so, here names of all the students are displayed when the Super-type Student is called.Note: