Skip to main content

Posts

Showing posts from May, 2023

Variance concepts in the context of parametric programming with Java

Variance concepts in the context of parametric programming with Java By Obed Rios (5/7/2023 ) Revision 1.0 Abstract In Java, the concepts of variance are related to how the type parameters of a class or interface are related to each other when the class or interface is sub-typed or implemented. The key difference between invariant and covariant in the context of Java generics is how they handle sub-typing relationships. Invariant types do not allow assignments between different type parameters, while covariant types can accept a specified type or any of its sub-types. In addition contravariance enables you to use a more general type (super type) in a generic type or method that would normally require a more specific type (sub-type). In this work, we show explicitly the concepts of variance in the context of Java Generics. Introduction Parametric variance refers to the relationship between the type parameters of a class or interface and their subtypes. It defines how subtyping is i...