Generic Variance — Motivation

An explanation of why it’s crucial to understand generic variance, why the compiler can’t do the work for us, and how even slight changes in class definitions can turn previously safe code into runtime errors waiting to happen.

Gabriel Shanahan
The Kotlin Primer

--

— — — — — — — — — — — — — — —

THE CURRENT VERSION OF THIS ARTICLE IS PUBLISHED HERE.

— — — — — — — — — — — — — — —

Tags: #FYI++

This article is part of the Kotlin Primer, an opinionated guide to the Kotlin language, which is indented to help facilitate Kotlin adoption inside Java-centric organizations. It was originally written as an organizational learning resource for Etnetera a.s. and I would like to express my sincere gratitude for their support.

It is recommended to read the Introduction before moving on. Check out the Table of Contents for all articles.

The topic of generic variance is one of those things that seem to be perceived as “advanced code-fu” and “only needed when doing advanced code-fu-stuff”, which, for most people, translates to “hopefully never-fuckin’-ever”.

--

--