# Generic Variance

DevFeed: [Generic Variance](<https://devfeed.tech/articles/generic-variance-25066.md>)

Original publisher: [Read original article](<https://typealias.com/start/kotlin-variance/>)

Author: author@typealias.com (Dave Leeds)

Published: 2024-04-23T00:00:00Z

Content type: tutorial

Language: en

Sources: [Dave Leeds on Kotlin - typealias.com](<https://devfeed.tech/sources/dave-leeds-on-kotlin-typealias-com.md>)

Topics: [generics](<https://devfeed.tech/topics/generics.md>), [Kotlin](<https://devfeed.tech/topics/kotlin.md>), [interfaces](<https://devfeed.tech/topics/interfaces.md>)

Tags: [advanced-kotlin-concepts](<https://devfeed.tech/tags/advanced-kotlin-concepts.md>), [contravariance](<https://devfeed.tech/tags/contravariance.md>), [covariance](<https://devfeed.tech/tags/covariance.md>), [extend](<https://devfeed.tech/tags/extend.md>), [generic-variance](<https://devfeed.tech/tags/generic-variance.md>), [generics](<https://devfeed.tech/tags/generics.md>), [implement](<https://devfeed.tech/tags/implement.md>), [interfaces](<https://devfeed.tech/tags/interfaces.md>), [introduction](<https://devfeed.tech/tags/introduction.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [kotlin-generics](<https://devfeed.tech/tags/kotlin-generics.md>), [kotlin-type-safety](<https://devfeed.tech/tags/kotlin-type-safety.md>), [learn-to-program](<https://devfeed.tech/tags/learn-to-program.md>), [programming](<https://devfeed.tech/tags/programming.md>), [programming-language-type-systems](<https://devfeed.tech/tags/programming-language-type-systems.md>), [software-development](<https://devfeed.tech/tags/software-development.md>), [subtyping-in-kotlin](<https://devfeed.tech/tags/subtyping-in-kotlin.md>), [type-parameters](<https://devfeed.tech/tags/type-parameters.md>)

## AI overview

A tutorial on variance in Kotlin generic types. It explains how covariance and contravariance affect subtype relationships between parameterized types, using examples to show when one generic type can substitute for another.

## Source excerpt

We've seen how we can implement interfaces and extend classes to create subtypes. However, with generic types, we sometimes want to create a subtype based on the type arguments instead of the base types. Kotlin gives us a few different tools to achieve this, and in this chapter we'll learn all about them. In order to understand how this is possible, we'll first need to understand the principles of variance. Then, we'll look at three simple rules that explain when one parameterized type can be the subtype of another.