Generic Type Variance: Invariance, Covariance, and Contravariance

While working with Spring Batch, I encountered ItemWriter’s method void write(List<? extends T> var1) and pondered the rationale for such generic type specification. I have finally undertaken comprehensive investigation. Contravariance concepts proved conceptually challenging, requiring several hours to achieve comprehension. However, upon understanding, the underlying principles appear remarkably straightforward. This exposition attempts maximal clarity. Generic Terminology Initially, I had forgotten even the appropriate search terminology, necessitating terminological review. These terms follow Effective Java conventions. ...

November 7, 2021 · 796 words · Mihyang Gu