KType

Common
JVM
JS
1.0
interface KType : KAnnotatedElement
Native
1.3
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

Common
JVM
JS
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>
Common
JVM
JS
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?
Common
JVM
JS
Native
1.0

isMarkedNullable

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

abstract val isMarkedNullable: Boolean

Extension Properties

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

JVM
1.1

findAnnotation

Returns an annotation of the given type on this element.

fun <T : Annotation> KAnnotatedElement.findAnnotation(): T?
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
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
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