# Use-Site Variance

Published articles for Use-Site Variance.

This is one page of public article previews, not the complete archive. Follow Next page to continue. Summaries are not the original full articles.

## Star-Projections and How They Work

DevFeed: [Star-Projections and How They Work](<https://devfeed.tech/articles/star-projections-and-how-they-work-25043.md>)

Original publisher: [Read original article](<https://typealias.com/guides/star-projections-and-how-they-work/>)

Author: author@typealias.com (Dave Leeds)

Published: 2018-04-05T00: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>)

Tags: [article](<https://devfeed.tech/tags/article.md>), [class](<https://devfeed.tech/tags/class.md>), [function](<https://devfeed.tech/tags/function.md>), [generic](<https://devfeed.tech/tags/generic.md>), [generic-variance](<https://devfeed.tech/tags/generic-variance.md>), [generics](<https://devfeed.tech/tags/generics.md>), [guide](<https://devfeed.tech/tags/guide.md>), [interface](<https://devfeed.tech/tags/interface.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [parameter](<https://devfeed.tech/tags/parameter.md>), [programming](<https://devfeed.tech/tags/programming.md>), [star-projection](<https://devfeed.tech/tags/star-projection.md>), [type-projection](<https://devfeed.tech/tags/type-projection.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 how Kotlin star-projections work when a function must accept any kind of a generic. It applies subtyping rules for accepted and returned types to compare star-projections with other type-safe solutions.

### Source excerpt

Have you ever wondered how star-projections work? Or why they change your function parameter and return types? Or why it seems like sometimes you can actually get by without them? In the first article in this series, An Illustrated Guide to Covariance and Contravariance in Kotlin, we uncovered two simple, easy-to-understand rules that illuminate variance, and saw how they applied to regular class and interface inheritance in Kotlin. In the second article, The Ins and Outs of Generic Variance in Kotlin, we saw how those same two rules played out for generics, discovering what type projections are and how they work.

## Out-Projection

DevFeed: [Out-Projection](<https://devfeed.tech/articles/out-projection-25020.md>)

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

Author: author@typealias.com (Dave Leeds)

Published: 2018-02-05T00: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>), [Code](<https://devfeed.tech/topics/code.md>)

Tags: [covariance](<https://devfeed.tech/tags/covariance.md>), [generic](<https://devfeed.tech/tags/generic.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [programming](<https://devfeed.tech/tags/programming.md>), [type-projection](<https://devfeed.tech/tags/type-projection.md>), [use-site-variance](<https://devfeed.tech/tags/use-site-variance.md>), [variance](<https://devfeed.tech/tags/variance.md>)

### AI overview

This tutorial explains Kotlin out-projections, showing how they provide covariance at a use site while preventing operations that accept the projected type parameter. It covers the type-safety limitation and when out-projections are useful compared with declaration-site variance.

### Source excerpt

An out-projection is a kind of type projection that makes a generic covariant, but also causes any functions that accept the type parameter to be unusable in that context. You can think of it this way - In regular life, when some three-dimensional thing casts a shadow, that shadow is a two-dimensional projection of the original object - it's an incomplete representation of it. In the same way, an out-projection is a limited view of the original class.

## Type Projection

DevFeed: [Type Projection](<https://devfeed.tech/articles/type-projection-25028.md>)

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

Author: author@typealias.com (Dave Leeds)

Published: 2017-12-27T18:18:01Z

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>), [Code](<https://devfeed.tech/topics/code.md>)

Tags: [compiler](<https://devfeed.tech/tags/compiler.md>), [declaration-site-variance](<https://devfeed.tech/tags/declaration-site-variance.md>), [generic](<https://devfeed.tech/tags/generic.md>), [generic-variance](<https://devfeed.tech/tags/generic-variance.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [object](<https://devfeed.tech/tags/object.md>), [operations](<https://devfeed.tech/tags/operations.md>), [programming](<https://devfeed.tech/tags/programming.md>), [type-projection](<https://devfeed.tech/tags/type-projection.md>), [use-site-variance](<https://devfeed.tech/tags/use-site-variance.md>), [variance](<https://devfeed.tech/tags/variance.md>)

### AI overview

This tutorial explains Kotlin type projection as a restricted view of an existing type that enables variance and subtyping in specific contexts. It describes how use-site variance produces projections and how projections can restrict operations such as setters.

### Source excerpt

A type projection is a type that has been limited in certain ways in order to gain variance characteristics. Imagine a three-dimensional object that you shine a flashlight onto. Behind that object on the wall is a two-dimensional projection of that object - a shadow. That projection has the same basic shape as the object, but only from one perspective. Type projection is kind of like that - we take an existing object and reduce it to just the attributes or operations that we need at that place in the code.

## 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.