Package kotlin.reflect.full

Extensions for Kotlin reflection provided by kotlin-reflect library.

Exceptions

JVM
1.1

IllegalCallableAccessException

An exception that is thrown when call is invoked on a callable or get or set is invoked on a property and that callable is not accessible (in JVM terms) from the calling method.

class IllegalCallableAccessException : Exception
JVM
1.1

IllegalPropertyDelegateAccessException

An exception that is thrown when getDelegate is invoked on a KProperty object that was not made accessible with isAccessible.

class IllegalPropertyDelegateAccessException : Exception
JVM
1.1

NoSuchPropertyException

An exception that is thrown when the code tries to introspect a property of a class or a package and that class or the package no longer has that property.

class NoSuchPropertyException : Exception

Properties

JVM
1.1

allSuperclasses

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.

val KClass<*>.allSuperclasses: Collection<KClass<*>>
JVM
1.1

allSupertypes

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.

val KClass<*>.allSupertypes: Collection<KType>
JVM
1.1

companionObject

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

val KClass<*>.companionObject: KClass<*>?
JVM
1.1

companionObjectInstance

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

val KClass<*>.companionObjectInstance: Any?
JVM
1.1

declaredFunctions

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.

val KClass<*>.declaredFunctions: Collection<KFunction<*>>
JVM
1.1

declaredMemberExtensionFunctions

Returns extension functions declared in this class.

val KClass<*>.declaredMemberExtensionFunctions: Collection<KFunction<*>>
JVM
1.1

declaredMemberExtensionProperties

Returns extension properties declared in this class.

val <T : Any> KClass<T>.declaredMemberExtensionProperties: Collection<KProperty2<T, *, *>>
JVM
1.1

declaredMemberFunctions

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

val KClass<*>.declaredMemberFunctions: Collection<KFunction<*>>
JVM
1.1

declaredMemberProperties

Returns non-extension properties declared in this class.

val <T : Any> KClass<T>.declaredMemberProperties: Collection<KProperty1<T, *>>
JVM
1.1

declaredMembers

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

val KClass<*>.declaredMembers: Collection<KCallable<*>>
JVM
1.1

defaultType

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

val KClass<*>.defaultType: KType
JVM
1.1

extensionReceiverParameter

Returns a parameter representing the extension receiver instance needed to call this callable, or null if this callable is not an extension.

val KCallable<*>.extensionReceiverParameter: KParameter?
JVM
1.1

functions

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.

val KClass<*>.functions: Collection<KFunction<*>>
JVM
1.1

instanceParameter

Returns a parameter representing the this instance needed to call this callable, or null if this callable is not a member of a class and thus doesn't take such parameter.

val KCallable<*>.instanceParameter: KParameter?
JVM
1.1

memberExtensionFunctions

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

val KClass<*>.memberExtensionFunctions: Collection<KFunction<*>>
JVM
1.1

memberExtensionProperties

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

val <T : Any> KClass<T>.memberExtensionProperties: Collection<KProperty2<T, *, *>>
JVM
1.1

memberFunctions

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

val KClass<*>.memberFunctions: Collection<KFunction<*>>
JVM
1.1

memberProperties

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

val <T : Any> KClass<T>.memberProperties: Collection<KProperty1<T, *>>
JVM
1.1

primaryConstructor

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

val <T : Any> KClass<T>.primaryConstructor: KFunction<T>?
JVM
1.1

starProjectedType

Creates an instance of KType with the given classifier, substituting all its type parameters with star projections. The resulting type is not marked as nullable and does not have any annotations.

val KClassifier.starProjectedType: KType
JVM
1.1

staticFunctions

Returns static functions declared in this class.

val KClass<*>.staticFunctions: Collection<KFunction<*>>
JVM
1.1

staticProperties

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

val KClass<*>.staticProperties: Collection<KProperty0<*>>
JVM
1.1

superclasses

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.

val KClass<*>.superclasses: List<KClass<*>>
JVM
1.1

valueParameters

Returns parameters of this callable, excluding the this instance and the extension receiver parameter.

val KCallable<*>.valueParameters: List<KParameter>

Functions

JVM
1.3

callSuspend

Calls a callable in the current suspend context. If the callable is not a suspend function, behaves as KCallable.call. Otherwise, calls the suspend function with current continuation.

suspend fun <R> KCallable<R>.callSuspend(
    vararg args: Any?
): R
JVM
1.3

callSuspendBy

Calls a callable in the current suspend context. If the callable is not a suspend function, behaves as KCallable.callBy. Otherwise, calls the suspend function with current continuation.

suspend fun <R> KCallable<R>.callSuspendBy(
    args: Map<KParameter, Any?>
): R
JVM
1.1

cast

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

createInstance

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.

fun <T : Any> KClass<T>.createInstance(): T
JVM
1.1

createType

Creates a KType instance with the given classifier, type arguments, nullability and annotations. If the number of passed type arguments is not equal to the total number of type parameters of a classifier, an exception is thrown. If any of the arguments does not satisfy the bounds of the corresponding type parameter, an exception is thrown.

fun KClassifier.createType(
    arguments: List<KTypeProjection> = emptyList(),
    nullable: Boolean = false,
    annotations: List<Annotation> = emptyList()
): KType
JVM
1.1

findAnnotation

Returns an annotation of the given type on this element.

fun <T : Annotation> KAnnotatedElement.findAnnotation(): T?
JVM
1.7

findAnnotations

Returns all annotations of the given type on this element, including individually applied annotations as well as repeated annotations.

fun <T : Annotation> KAnnotatedElement.findAnnotations(): List<T>
fun <T : Annotation> KAnnotatedElement.findAnnotations(
    klass: KClass<T>
): List<T>
JVM
1.1

findParameterByName

Returns the parameter of this callable with the given name, or null if there's no such parameter.

fun KCallable<*>.findParameterByName(
    name: String
): KParameter?
JVM
1.1

getExtensionDelegate

Returns the instance of a delegated extension property, or null if this property is not delegated. Throws an exception if this is not an extension property.

fun KProperty1<*, *>.getExtensionDelegate(): Any?

Returns the instance of a delegated member extension property, or null if this property is not delegated. Throws an exception if this is not an extension property.

fun <D> KProperty2<D, *, *>.getExtensionDelegate(
    receiver: D
): Any?
JVM
1.4

hasAnnotation

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

fun <T : Annotation> KAnnotatedElement.hasAnnotation(): Boolean
JVM
1.1

isSubclassOf

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

fun KClass<*>.isSubclassOf(base: KClass<*>): Boolean
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

isSuperclassOf

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

fun KClass<*>.isSuperclassOf(derived: KClass<*>): 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

safeCast

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