W3cubDocs

/Kotlin

KVariance

Platform and version requirements: JVM (1.1), JS (1.1), Native (1.1)
enum class KVariance

Represents variance applied to a type parameter on the declaration site (declaration-site variance), or to a type in a projection (use-site variance).

See the Kotlin language documentation for more information.

See Also

KTypeParameter.variance

KTypeProjection

Enum Values

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

INVARIANT

The affected type parameter or type is invariant, which means it has no variance applied to it.

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

IN

The affected type parameter or type is contravariant. Denoted by the in modifier in the source code.

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

OUT

The affected type parameter or type is covariant. Denoted by the out modifier in the source code.

Extension Functions

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

coerceAtLeast

Ensures that this value is not less than the specified minimumValue.

fun <T : Comparable<T>> T.coerceAtLeast(minimumValue: T): T
Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)

coerceAtMost

Ensures that this value is not greater than the specified maximumValue.

fun <T : Comparable<T>> T.coerceAtMost(maximumValue: T): T
Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)

coerceIn

Ensures that this value lies in the specified range minimumValue..maximumValue.

fun <T : Comparable<T>> T.coerceIn(
    minimumValue: T?, 
    maximumValue: T?
): T

Ensures that this value lies in the specified range.

fun <T : Comparable<T>> T.coerceIn(
    range: ClosedFloatingPointRange<T>
): T
fun <T : Comparable<T>> T.coerceIn(range: ClosedRange<T>): T
Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)

rangeTo

Creates a range from this Comparable value to the specified that value.

operator fun <T : Comparable<T>> T.rangeTo(
    that: T
): ClosedRange<T>

© 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-variance/index.html