Package kotlin.reflect
Runtime API for Kotlin reflection
Types
Platform and version requirements: JVM (1.0), Native (1.0)
Represents an annotated element and allows to obtain its annotations. See the Kotlin language documentation for more information.
interface KAnnotatedElement
Represents a callable entity, such as a function or a property.
Platform and version requirements: JS (1.1)
interface KCallable<out R>
Platform and version requirements: JVM (1.0), Native (1.3)
interface KCallable<out R> : KAnnotatedElement
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.
Platform and version requirements: JS (1.1)
interface KClass<T : Any> : KClassifier
Platform and version requirements: JVM (1.0), Native (1.3)
interface KClass<T : Any> :
KDeclarationContainer,
KAnnotatedElement,
KClassifier
Platform and version requirements: JVM (1.1), JS (1.1), Native (1.1)
A classifier is either a class or a type parameter.
Platform and version requirements: JVM (1.0), Native (1.0)
Represents an entity which may contain declarations of any other entities, such as a class or a package.
interface KDeclarationContainer
Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)
Represents a function with introspection capabilities.
interface KFunction<out R> : KCallable<R>, Function<R>
Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)
Represents a property declared as a var
.
interface KMutableProperty<V> : KProperty<V>
Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)
Represents a var
-property without any kind of receiver.
interface KMutableProperty0<V> :
KProperty0<V>,
KMutableProperty<V>
Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)
Represents a var
-property, operations on which take one receiver as a parameter.
interface KMutableProperty1<T, V> :
KProperty1<T, V>,
KMutableProperty<V>
Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)
Represents a var
-property, operations on which take two receivers as parameters.
interface KMutableProperty2<D, E, V> :
KProperty2<D, E, V>,
KMutableProperty<V>
Platform and version requirements: JVM (1.0)
Represents a parameter passed to a function or a property getter/setter, including this
and extension receiver parameters.
interface KParameter : KAnnotatedElement
Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)
Represents a property, such as a named val
or var
declaration. Instances of this class are obtainable by the ::
operator.
interface KProperty<out V> : KCallable<V>
Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)
Represents a property without any kind of receiver. Such property is either originally declared in a receiverless context such as a package, or has the receiver bound to it.
interface KProperty0<out V> : KProperty<V>, () -> V
Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)
Represents a property, operations on which take one receiver as a parameter.
interface KProperty1<T, out V> : KProperty<V>, (T) -> V
Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)
Represents a property, operations on which take two receivers as parameters, such as an extension property declared in a class.
interface KProperty2<D, E, out V> : KProperty<V>, (D, E) -> V
Represents a type. Type is usually either a class with optional type arguments, or a type parameter of some declaration, plus nullability.
Platform and version requirements: JS (1.1), Native (1.3)
interface KType
Platform and version requirements: JVM (1.0)
interface KType : KAnnotatedElement
Platform and version requirements: JVM (1.1), JS (1.1), Native (1.1)
Represents a declaration of a type parameter of a class or a callable. See the Kotlin language documentation for more information.
interface KTypeParameter : KClassifier
Platform and version requirements: JVM (1.1), JS (1.1), Native (1.1)
Represents a type projection. Type projection is usually the argument to another type in a type usage. For example, in the type Array<out Number>
, out Number
is the covariant projection of the type represented by the class Number
.
data class KTypeProjection
Platform and version requirements: JVM (1.1), JS (1.1), Native (1.1)
Represents variance applied to a type parameter on the declaration site (declaration-site variance), or to a type in a projection (use-site variance).
Platform and version requirements: JVM (1.1)
Visibility is an aspect of a Kotlin declaration regulating where that declaration is accessible in the source code. Visibility can be changed with one of the following modifiers: public
, protected
, internal
, private
.
Annotations
Platform and version requirements: JS (1.1), Native (1.1)
Makes the annotated annotation class an associated object key.
annotation class AssociatedObjectKey
Platform and version requirements: JS (1.1), Native (1.1)
The experimental marker for associated objects API.
annotation class ExperimentalAssociatedObjects
Properties
Platform and version requirements: JVM (1.4)
Returns a Java Type instance corresponding to the given Kotlin type.
Functions
Platform and version requirements: JVM (1.4), JS (1.4), Native (1.4)
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
Platform and version requirements: JS (1.1), Native (1.1)
If T is an @AssociatedObjectKey-annotated annotation class and this class is annotated with @T (S::class
), returns object S
.
fun <T : Annotation> KClass<*>.findAssociatedObject(): Any?
Platform and version requirements: JVM (1.4), JS (1.4), Native (1.4)
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?
Platform and version requirements: JVM (1.3), JS (1.3), Native (1.3)
Returns a runtime representation of the given reified type T as an instance of KType.