# Variance Annotation

DevFeed: [Variance Annotation](<https://devfeed.tech/articles/variance-annotation-25029.md>)

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

Author: author@typealias.com (Dave Leeds)

Published: 2017-12-04T02:49:24Z

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>), [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>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [parameter](<https://devfeed.tech/tags/parameter.md>), [programming](<https://devfeed.tech/tags/programming.md>), [subtype](<https://devfeed.tech/tags/subtype.md>), [type-argument](<https://devfeed.tech/tags/type-argument.md>), [types](<https://devfeed.tech/tags/types.md>), [use-site-variance](<https://devfeed.tech/tags/use-site-variance.md>), [variance](<https://devfeed.tech/tags/variance.md>)

## AI overview

This tutorial explains variance annotations in Kotlin generics. It covers the out modifier for covariance, the in modifier for contravariance, and the invariant behavior when no variance annotation is declared.

## Source excerpt

A variance annotation is a modifier applied to a type parameter or type argument of a generic, in order to declare its variance. Kotlin defines two variance annotations in its grammar: out and in. out The out modifier is used to declare a type parameter as being covariant. For example: class Box<out T>(private val item: T) { fun getItem(): T = item } With the out variance annotation declared on the type parameter T in this class, subtyping rules can now be applied to Boxes of different types.