Scala – Variance

  • date 18th February, 2021 |
  • by Prwatech |
  • 0 Comments

Variance

Variance is the correlation between the subtyping relationships of complex types and the subtyping relationships of their component types.

Covariance

A type parameter T of a generic class can be made covariant by using the annotation +T.

Here is the program for your reference:

This image has an empty alt attribute; its file name is Screenshot-506.png

Contravariance

A type parameter A of a generic class can be made contravariant by using the annotation -A.

Invariance

Generic classes in Scala are invariant by default.

Quick Support

image image