W3cubDocs

/Kotlin

KType

interface KType

Represents a type. Type is usually either a class with optional type arguments, or a type parameter of some declaration, plus nullability.

Properties

arguments

abstract val arguments: List<KTypeProjection>

Type arguments passed for the parameters of the classifier in this type. For example, in the type Array<out Number> the only type argument is out Number.

classifier

abstract val classifier: KClassifier?

The declaration of the classifier used in this type. For example, in the type List<String> the classifier would be the KClass instance for List.

isMarkedNullable

abstract val isMarkedNullable: Boolean

true if this type was marked nullable in the source code.

Inherited Functions

equals

open operator fun equals(other: Any?): Boolean

Indicates whether some other object is "equal to" this one. Implementations must fulfil the following requirements:

hashCode

open fun hashCode(): Int

Returns a hash code value for the object. The general contract of hashCode is:

toString

open fun toString(): String

Returns a string representation of the object.

Extension Properties

javaType

val KType.javaType: Type

Returns a Java Type instance corresponding to the given Kotlin type. Note that one Kotlin type may correspond to different JVM types depending on where it appears. For example, Unit corresponds to the JVM class Unit when it's the type of a parameter, or to void when it's the return type of a function.

jvmErasure

val KType.jvmErasure: KClass<*>

Returns the KClass instance representing the runtime class to which this type is erased to on JVM.

Extension Functions

isSubtypeOf

fun KType.isSubtypeOf(other: KType): Boolean

Returns true if this type is the same or is a subtype of other, false otherwise.

isSupertypeOf

fun KType.isSupertypeOf(other: KType): Boolean

Returns true if this type is the same or is a supertype of other, false otherwise.

withNullability

fun KType.withNullability(nullable: Boolean): KType

Returns a new type with the same classifier, arguments and annotations as the given type, and with the given nullability.

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