KClass

expect interface KClass<T : Any> : KClassifier

Represents a class and provides introspection capabilities. Instances of this class are obtainable by the ::class syntax. See the Kotlin language documentation for more information.

actual interface KClass<T : Any> : KDeclarationContainer, KAnnotatedElement, KClassifier

Represents a class and provides introspection capabilities. Instances of this class are obtainable by the ::class syntax. See the Kotlin language documentation for more information.

actual interface KClass<T : Any> : KClassifier

Represents a class and provides introspection capabilities. Instances of this class are obtainable by the ::class syntax. See the Kotlin language documentation for more information.

actual interface KClass<T : Any> : KDeclarationContainer, KAnnotatedElement, KClassifier

Represents a class and provides introspection capabilities. Instances of this class are obtainable by the ::class syntax. See the Kotlin language documentation for more information.

Parameters

T

the type of the class.

T

the type of the class.

T

the type of the class.

T

the type of the class.

Functions

equals
Link copied to clipboard
abstract operator override fun equals(other: Any?): Boolean

Returns true if this KClass instance represents the same Kotlin class as the class represented by other. On JVM this means that all of the following conditions are satisfied:

abstract operator override fun equals(other: Any?): Boolean

Returns true if this KClass instance represents the same Kotlin class as the class represented by other. On JVM this means that all of the following conditions are satisfied:

abstract operator override fun equals(other: Any?): Boolean

Returns true if this KClass instance represents the same Kotlin class as the class represented by other. On JVM this means that all of the following conditions are satisfied:

hashCode
Link copied to clipboard
abstract override fun hashCode(): Int
abstract override fun hashCode(): Int
abstract override fun hashCode(): Int
isInstance
Link copied to clipboard
expect abstract fun isInstance(value: Any?): Boolean

Returns true if value is an instance of this class on a given platform.

Since Kotlin

1.1
actual abstract fun isInstance(value: Any?): Boolean

Returns true if value is an instance of this class on a given platform.

Since Kotlin

1.1
actual abstract fun isInstance(value: Any?): Boolean

Returns true if value is an instance of this class on a given platform.

Since Kotlin

1.1
actual abstract fun isInstance(value: Any?): Boolean

Returns true if value is an instance of this class on a given platform.

Since Kotlin

1.1

Properties

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

Annotations which are present on this element.

constructors
Link copied to clipboard
abstract val constructors: Collection<KFunction<T>>

All constructors declared in this class.

isAbstract
Link copied to clipboard
abstract val isAbstract: Boolean

true if this class is abstract.

isCompanion
Link copied to clipboard
abstract val isCompanion: Boolean

true if this class is a companion object. See the Kotlin language documentation for more information.

isData
Link copied to clipboard
abstract val isData: Boolean

true if this class is a data class. See the Kotlin language documentation for more information.

isFinal
Link copied to clipboard
abstract val isFinal: Boolean

true if this class is final.

isFun
Link copied to clipboard
abstract val isFun: Boolean

true if this class is a Kotlin functional interface.

isInner
Link copied to clipboard
abstract val isInner: Boolean

true if this class is an inner class. See the Kotlin language documentation for more information.

isOpen
Link copied to clipboard
abstract val isOpen: Boolean

true if this class is open.

isSealed
Link copied to clipboard
abstract val isSealed: Boolean

true if this class is sealed. See the Kotlin language documentation for more information.

isValue
Link copied to clipboard
abstract val isValue: Boolean

true if this class is a value class.

members
Link copied to clipboard
abstract override val members: Collection<KCallable<*>>

All functions and properties accessible in this class, including those declared in this class and all of its superclasses. Does not include constructors.

nestedClasses
Link copied to clipboard
abstract val nestedClasses: Collection<KClass<*>>

All classes declared inside this class. This includes both inner and static nested classes.

objectInstance
Link copied to clipboard
abstract val objectInstance: T?

The instance of the object declaration, or null if this class is not an object declaration.

qualifiedName
Link copied to clipboard
expect abstract val qualifiedName: String?

The fully qualified dot-separated name of the class, or null if the class is local or a class of an anonymous object.

actual abstract val qualifiedName: String?

The fully qualified dot-separated name of the class, or null if the class is local or a class of an anonymous object.

actual abstract val qualifiedName: String?

The fully qualified dot-separated name of the class, or null if the class is local or a class of an anonymous object.

actual abstract val qualifiedName: String?

The fully qualified dot-separated name of the class, or null if the class is local or a class of an anonymous object.

sealedSubclasses
Link copied to clipboard
abstract val sealedSubclasses: List<KClass<out T>>

The list of the immediate subclasses if this class is a sealed class, or an empty list otherwise.

simpleName
Link copied to clipboard
expect abstract val simpleName: String?

The simple name of the class as it was declared in the source code, or null if the class has no name (if, for example, it is a class of an anonymous object).

actual abstract val simpleName: String?

The simple name of the class as it was declared in the source code, or null if the class has no name (if, for example, it is a class of an anonymous object).

actual abstract val simpleName: String?

The simple name of the class as it was declared in the source code, or null if the class has no name (if, for example, it is a class of an anonymous object).

actual abstract val simpleName: String?

The simple name of the class as it was declared in the source code, or null if the class has no name (if, for example, it is a class of an anonymous object).

supertypes
Link copied to clipboard
abstract val supertypes: List<KType>

The list of immediate supertypes of this class, in the order they are listed in the source code.

typeParameters
Link copied to clipboard
abstract val typeParameters: List<KTypeParameter>

The list of type parameters of this class. This list does not include type parameters of outer classes.

visibility
Link copied to clipboard
abstract val visibility: KVisibility?

Visibility of this class, or null if its visibility cannot be represented in Kotlin.

Extensions

allSuperclasses
Link copied to clipboard
val KClass<*>.allSuperclasses: Collection<KClass<*>>

All superclasses of this class, including indirect ones, in no particular order. Includes superclasses and superinterfaces of the class, but does not include the class itself. The returned collection does not contain more than one instance of any given class.

allSupertypes
Link copied to clipboard
val KClass<*>.allSupertypes: Collection<KType>

All supertypes of this class, including indirect ones, in no particular order. There is not more than one type in the returned collection that has any given classifier.

cast
Link copied to clipboard
fun <T : Any> KClass<T>.cast(value: Any?): T

Casts the given value to the class represented by this KClass object. Throws an exception if the value is null or if it is not an instance of this class.

fun <T : Any> KClass<T>.cast(value: Any?): T

Casts the given value to the class represented by this KClass object. Throws an exception if the value is null or if it is not an instance of this class.

companionObject
Link copied to clipboard
val KClass<*>.companionObject: KClass<*>?

Returns a KClass instance representing the companion object of a given class, or null if the class doesn't have a companion object.

companionObjectInstance
Link copied to clipboard
val KClass<*>.companionObjectInstance: Any?

Returns an instance of the companion object of a given class, or null if the class doesn't have a companion object.

createInstance
Link copied to clipboard
fun <T : Any> KClass<T>.createInstance(): T

Creates a new instance of the class, calling a constructor which either has no parameters or all parameters of which are optional (see KParameter.isOptional). If there are no or many such constructors, an exception is thrown.

declaredFunctions
Link copied to clipboard
val KClass<*>.declaredFunctions: Collection<KFunction<*>>

Returns all functions declared in this class. If this is a Java class, it includes all non-static methods (both extensions and non-extensions) declared in the class and the superclasses, as well as static methods declared in the class.

declaredMemberExtensionFunctions
Link copied to clipboard
val KClass<*>.declaredMemberExtensionFunctions: Collection<KFunction<*>>

Returns extension functions declared in this class.

declaredMemberExtensionProperties
Link copied to clipboard
val <T : Any> KClass<T>.declaredMemberExtensionProperties: Collection<KProperty2<T, *, *>>

Returns extension properties declared in this class.

declaredMemberFunctions
Link copied to clipboard
val KClass<*>.declaredMemberFunctions: Collection<KFunction<*>>

Returns non-extension non-static functions declared in this class.

declaredMemberProperties
Link copied to clipboard
val <T : Any> KClass<T>.declaredMemberProperties: Collection<KProperty1<T, *>>

Returns non-extension properties declared in this class.

declaredMembers
Link copied to clipboard
val KClass<*>.declaredMembers: Collection<KCallable<*>>

Returns all functions and properties declared in this class. Does not include members declared in supertypes.

defaultType
Link copied to clipboard
val KClass<*>.defaultType: KType

Returns a type corresponding to the given class with type parameters of that class substituted as the corresponding arguments. For example, for class MyMap<K, V>defaultType would return the type MyMap<K, V>.

findAssociatedObject
Link copied to clipboard
inline fun <T : Annotation> KClass<*>.findAssociatedObject(): Any?

If T is an @AssociatedObjectKey-annotated annotation class and this class is annotated with @T (S::class), returns object S.

inline fun <T : Annotation> KClass<*>.findAssociatedObject(): Any?

If T is an @AssociatedObjectKey-annotated annotation class and this class is annotated with @T (S::class), returns object S.

functions
Link copied to clipboard
val KClass<*>.functions: Collection<KFunction<*>>

Returns all functions declared in this class, including all non-static methods declared in the class and the superclasses, as well as static methods declared in the class.

isSubclassOf
Link copied to clipboard
fun KClass<*>.isSubclassOf(base: KClass<*>): Boolean

Returns true if this class is the same or is a (possibly indirect) subclass of base, false otherwise.

isSuperclassOf
Link copied to clipboard
fun KClass<*>.isSuperclassOf(derived: KClass<*>): Boolean

Returns true if this class is the same or is a (possibly indirect) superclass of derived, false otherwise.

java
Link copied to clipboard
@get:JvmName(name = "getJavaClass")
val <T> KClass<T>.java: Class<T>
@get:JvmName(name = "getJavaClass")
val <T> KClass<T>.java: Class<T>

Returns a Java Class instance corresponding to the given KClass instance.

javaClass
Link copied to clipboard
@get:JvmName(name = "getRuntimeClassOfKClassInstance")
val <T : Any> KClass<T>.javaClass: Class<KClass<T>>
@get:JvmName(name = "getRuntimeClassOfKClassInstance")
val <T : Any> KClass<T>.javaClass: Class<KClass<T>>
javaObjectType
Link copied to clipboard
val <T : Any> KClass<T>.javaObjectType: Class<T>
val <T : Any> KClass<T>.javaObjectType: Class<T>

Returns a Java Class instance corresponding to the given KClass instance. In case of primitive types it returns corresponding wrapper classes.

javaPrimitiveType
Link copied to clipboard
val <T : Any> KClass<T>.javaPrimitiveType: Class<T>?
val <T : Any> KClass<T>.javaPrimitiveType: Class<T>?

Returns a Java Class instance representing the primitive type corresponding to the given KClass if it exists.

js
Link copied to clipboard
val <T : Any> KClass<T>.js: JsClass<T>

Obtains a constructor reference for the given KClass.

jvmName
Link copied to clipboard
val KClass<*>.jvmName: String

Returns the JVM name of the class represented by this KClass instance.

memberExtensionFunctions
Link copied to clipboard
val KClass<*>.memberExtensionFunctions: Collection<KFunction<*>>

Returns extension functions declared in this class and all of its superclasses.

memberExtensionProperties
Link copied to clipboard
val <T : Any> KClass<T>.memberExtensionProperties: Collection<KProperty2<T, *, *>>

Returns extension properties declared in this class and all of its superclasses.

memberFunctions
Link copied to clipboard
val KClass<*>.memberFunctions: Collection<KFunction<*>>

Returns non-extension non-static functions declared in this class and all of its superclasses.

memberProperties
Link copied to clipboard
val <T : Any> KClass<T>.memberProperties: Collection<KProperty1<T, *>>

Returns non-extension properties declared in this class and all of its superclasses.

primaryConstructor
Link copied to clipboard
val <T : Any> KClass<T>.primaryConstructor: KFunction<T>?

Returns the primary constructor of this class, or null if this class has no primary constructor. See the Kotlin language documentation for more information.

safeCast
Link copied to clipboard
fun <T : Any> KClass<T>.safeCast(value: Any?): T?

Casts the given value to the class represented by this KClass object. Returns null if the value is null or if it is not an instance of this class.

fun <T : Any> KClass<T>.safeCast(value: Any?): T?

Casts the given value to the class represented by this KClass object. Returns null if the value is null or if it is not an instance of this class.

staticFunctions
Link copied to clipboard
val KClass<*>.staticFunctions: Collection<KFunction<*>>

Returns static functions declared in this class.

staticProperties
Link copied to clipboard
val KClass<*>.staticProperties: Collection<KProperty0<*>>

Returns static properties declared in this class. Only properties representing static fields of Java classes are considered static.

superclasses
Link copied to clipboard
val KClass<*>.superclasses: List<KClass<*>>

Immediate superclasses of this class, in the order they are listed in the source code. Includes superclasses and superinterfaces of the class, but does not include the class itself.