interface KType (source)

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



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.


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.


abstract val isMarkedNullable: Boolean

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

Inherited Functions


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

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


open fun hashCode(): Int

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


open fun toString(): String

Returns a string representation of the object.

Extension Properties


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.


val KType.jvmErasure: KClass<*>

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

Extension Functions


fun KType.isSubtypeOf(other: KType): Boolean

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


fun KType.isSupertypeOf(other: KType): Boolean

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


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.