W3cubDocs

/Kotlin

KType

Platform and version requirements: JS (1.1), Native (1.3)
interface KType
Platform and version requirements: JVM (1.0)
interface KType : KAnnotatedElement

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

Properties

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

arguments

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.

abstract val arguments: List<KTypeProjection>
Platform and version requirements: JVM (1.1), JS (1.1), Native (1.1)

classifier

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.

abstract val classifier: KClassifier?
Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)

isMarkedNullable

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

abstract val isMarkedNullable: Boolean

Inherited Properties

Platform and version requirements: JVM (1.0)

annotations

Annotations which are present on this element.

abstract val annotations: List<Annotation>

Extension Properties

Platform and version requirements: JVM (1.4)

javaType

Returns a Java Type instance corresponding to the given Kotlin type.

val KType.javaType: Type
Platform and version requirements: JVM (1.0)

javaType

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.

val KType.javaType: Type
Platform and version requirements: JVM (1.1)

jvmErasure

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

val KType.jvmErasure: KClass<*>

Extension Functions

Platform and version requirements: JVM (1.1)

findAnnotation

Returns an annotation of the given type on this element.

fun <T : Annotation> KAnnotatedElement.findAnnotation(): T?
Platform and version requirements: JVM (1.4)

hasAnnotation

Returns true if this element is annotated with an annotation of type T.

fun <T : Annotation> KAnnotatedElement.hasAnnotation(): Boolean
Platform and version requirements: JVM (1.1)

isSubtypeOf

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

fun KType.isSubtypeOf(other: KType): Boolean
Platform and version requirements: JVM (1.1)

isSupertypeOf

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

fun KType.isSupertypeOf(other: KType): Boolean
Platform and version requirements: JVM (1.1)

withNullability

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

fun KType.withNullability(nullable: Boolean): KType

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