# The Ins and Outs of Generic Variance in Kotlin

DevFeed: [The Ins and Outs of Generic Variance in Kotlin](<https://devfeed.tech/articles/the-ins-and-outs-of-generic-variance-in-kotlin-25037.md>)

Original publisher: [Read original article](<https://typealias.com/guides/ins-and-outs-of-generic-variance/>)

Author: author@typealias.com (Dave Leeds)

Published: 2018-03-14T00: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: [Kotlin](<https://devfeed.tech/topics/kotlin.md>), [generics](<https://devfeed.tech/topics/generics.md>), [Compiler](<https://devfeed.tech/topics/compiler.md>)

Tags: [class](<https://devfeed.tech/tags/class.md>), [code](<https://devfeed.tech/tags/code.md>), [compiler](<https://devfeed.tech/tags/compiler.md>), [contravariance](<https://devfeed.tech/tags/contravariance.md>), [covariance](<https://devfeed.tech/tags/covariance.md>), [function](<https://devfeed.tech/tags/function.md>), [generic-variance](<https://devfeed.tech/tags/generic-variance.md>), [generics](<https://devfeed.tech/tags/generics.md>), [guide](<https://devfeed.tech/tags/guide.md>), [inheritance](<https://devfeed.tech/tags/inheritance.md>), [interface](<https://devfeed.tech/tags/interface.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [programming](<https://devfeed.tech/tags/programming.md>), [type-parameter](<https://devfeed.tech/tags/type-parameter.md>), [variance](<https://devfeed.tech/tags/variance.md>)

## AI overview

A tutorial explaining generic variance and type projections in Kotlin. It applies two subtype rules to show why covariance and contravariance work and uses a generic animal collection as an example.

## Source excerpt

Have you ever wondered why generic variance works like it does? Or why Kotlin won't let you use a type parameter as an argument when it's marked as out? Have you wondered why the compiler sometimes won't let you call a certain function on a generic? Yes, generics can seem mysterious, but with just two simple, easy-to-understand rules, we can reason our way through almost everything related to variance.