scala variances

Scala Variances: Covariance, Contravariance, and Invariance

Reading Time: 4 minutes 1. Variance Variance is the interconnection of subtyping relationship between complex types and their component types. Variance is all about sub-typing. It tells us if a type constructor is a subtype of another type constructor. Variance defines inheritance relationships of parameterized types(types that have parameters within them). Sub-Typing Every programming language supports the concept of types. Types give information about how to handle values at Continue Reading

Scala: Generic classes and Variance

Reading Time: 4 minutes Generic classes are classes which take a type as a parameter. This means, one class can be used with different types without actually writing down it multiple times. They are particularly useful for collection classes. Defining a generic class: Generic classes take a type as a parameter within square brackets [ ]. One convention is to use the letter A as type parameter identifier, though Continue Reading