W3cubDocs

/Kotlin

KTypeProjection

Platform and version requirements: JVM (1.1), JS (1.1), Native (1.1)
data class KTypeProjection

Represents a type projection. Type projection is usually the argument to another type in a type usage. For example, in the type Array<out Number>, out Number is the covariant projection of the type represented by the class Number.

Type projection is either the star projection, or an entity consisting of a specific type plus optional variance.

See the Kotlin language documentation for more information.

Constructors

Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)

<init>

Represents a type projection. Type projection is usually the argument to another type in a type usage. For example, in the type Array<out Number>, out Number is the covariant projection of the type represented by the class Number.

KTypeProjection(variance: KVariance?, type: KType?)

Properties

Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)

type

The type specified in the projection, or null if this is a star projection.

val type: KType?
Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)

variance

The use-site variance specified in the projection, or null if this is a star projection.

val variance: KVariance?

Functions

Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)

toString

Returns a string representation of the object.

fun toString(): String

Companion Object Properties

Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)

STAR

Star projection, denoted by the * character. For example, in the type KClass<*>, * is the star projection. See the Kotlin language documentation for more information.

val STAR: KTypeProjection

Companion Object Functions

Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)

contravariant

Creates a contravariant projection of a given type, denoted by the in modifier applied to a type. For example, in the type MutableList<in Number>, in Number is a contravariant projection of the type of class Number.

fun contravariant(type: KType): KTypeProjection
Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)

covariant

Creates a covariant projection of a given type, denoted by the out modifier applied to a type. For example, in the type Array<out Number>, out Number is a covariant projection of the type of class Number.

fun covariant(type: KType): KTypeProjection
Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)

invariant

Creates an invariant projection of a given type. Invariant projection is just the type itself, without any use-site variance modifiers applied to it. For example, in the type Set<String>, String is an invariant projection of the type represented by the class String.

fun invariant(type: KType): KTypeProjection

© 2010–2020 JetBrains s.r.o. and Kotlin Programming Language contributors
Licensed under the Apache License, Version 2.0.
https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.reflect/-k-type-projection/index.html