# Declaration-Site Variance

DevFeed: [Declaration-Site Variance](<https://devfeed.tech/articles/declaration-site-variance-25012.md>)

Original publisher: [Read original article](<https://typealias.com/concepts/declaration-site-variance/>)

Author: author@typealias.com (Dave Leeds)

Published: 2018-01-17T00: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>)

Tags: [class](<https://devfeed.tech/tags/class.md>), [compiler](<https://devfeed.tech/tags/compiler.md>), [covariance](<https://devfeed.tech/tags/covariance.md>), [declaration-site-variance](<https://devfeed.tech/tags/declaration-site-variance.md>), [function](<https://devfeed.tech/tags/function.md>), [generic](<https://devfeed.tech/tags/generic.md>), [interface](<https://devfeed.tech/tags/interface.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [programming](<https://devfeed.tech/tags/programming.md>), [property](<https://devfeed.tech/tags/property.md>), [type-parameter](<https://devfeed.tech/tags/type-parameter.md>), [variance](<https://devfeed.tech/tags/variance.md>)

## AI overview

This tutorial explains Kotlin declaration-site variance, including the in and out annotations, the restrictions they impose on type parameters, and the resulting subtyping relationships such as covariance.

## Source excerpt

Declaration-Site Variance is variance that is specified at the point where the generic is defined - for example, in the definition of the class, interface, function, or extension property. To use declaration-site variance, you just have to modify a type parameter with either the in or out variance annotation. By doing this, you limit where you're allowed to use the type parameter, but you also introduce subtyping for your generic, so that, for example, a Box<Dog> can be a subtype of Box<Animal>, whereas otherwise this wouldn't be possible.