Package kotlin.reflect.jvm

Runtime API for interoperability between /docs/reference/reflection.html and Java reflection provided by kotlin-reflect library.

Types

ExperimentalReflectionOnLambdas
Link copied to clipboard

This annotation marks the experimental kotlin-reflect API that allows to approximate a Kotlin lambda or a function expression instance to a KFunction instance. The behavior of this API may be changed or the API may be removed completely in any further release.

Since Kotlin

1.5

Functions

reflect
Link copied to clipboard
fun <R> Function<R>.reflect(): KFunction<R>?

This is an experimental API. Given a class for a compiled Kotlin lambda or a function expression, returns a KFunction instance providing introspection capabilities for that lambda or function expression and its parameters. Not all features are currently supported, in particular KCallable.call and KCallable.callBy will fail at the moment.

Properties

isAccessible
Link copied to clipboard
var KCallable<*>.isAccessible: Boolean

Provides a way to suppress JVM access checks for a callable.

javaConstructor
Link copied to clipboard
val <T> KFunction<T>.javaConstructor: Constructor<T>?

Returns a Java Constructor instance corresponding to the given Kotlin function, or null if this function is not a constructor or cannot be represented by a Java Constructor.

javaField
Link copied to clipboard
val KProperty<*>.javaField: Field?

Returns a Java Field instance corresponding to the backing field of the given property, or null if the property has no backing field.

javaGetter
Link copied to clipboard
val KProperty<*>.javaGetter: Method?

Returns a Java Method instance corresponding to the getter of the given property, or null if the property has no getter, for example in case of a simple private val in a class.

javaMethod
Link copied to clipboard
val KFunction<*>.javaMethod: Method?

Returns a Java Method instance corresponding to the given Kotlin function, or null if this function is a constructor or cannot be represented by a Java Method.

javaSetter
Link copied to clipboard
val KMutableProperty<*>.javaSetter: Method?

Returns a Java Method instance corresponding to the setter of the given mutable property, or null if the property has no setter, for example in case of a simple private var in a class.

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

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

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

kotlinFunction
Link copied to clipboard
val Method.kotlinFunction: KFunction<*>?

Returns a KFunction instance corresponding to the given Java Method instance, or null if this method cannot be represented by a Kotlin function.

kotlinFunction
Link copied to clipboard
val <T : Any> Constructor<T>.kotlinFunction: KFunction<T>?

Returns a KFunction instance corresponding to the given Java Constructor instance, or null if this constructor cannot be represented by a Kotlin function (for example, if it is a synthetic constructor).

kotlinProperty
Link copied to clipboard
val Field.kotlinProperty: KProperty<*>?

Returns a KProperty instance corresponding to the given Java Field instance, or null if this field cannot be represented by a Kotlin property (for example, if it is a synthetic field).