KType

expect interface KType

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

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

actual interface KType

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

actual 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

annotations
Link copied to clipboard
abstract val annotations: List<Annotation>

Annotations which are present on this element.

arguments
Link copied to clipboard
expect 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.

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

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

actual 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
Link copied to clipboard
expect 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.

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

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

actual 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
Link copied to clipboard
expect abstract val isMarkedNullable: Boolean

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

actual abstract val isMarkedNullable: Boolean

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

actual abstract val isMarkedNullable: Boolean

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

actual abstract val isMarkedNullable: Boolean

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

Extensions

isSubtypeOf
Link copied to clipboard
fun KType.isSubtypeOf(other: KType): Boolean

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

isSupertypeOf
Link copied to clipboard
fun KType.isSupertypeOf(other: KType): Boolean

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

javaType
Link copied to clipboard
@ExperimentalStdlibApi
val KType.javaType: Type

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

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
Link copied to clipboard
val KType.jvmErasure: KClass<*>

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

withNullability
Link copied to clipboard
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.