KFunction

Common
JVM
JS
Native
1.0

Represents a function with introspection capabilities.

Properties

JVM
1.1

isExternal

true if this function is external. See the Kotlin language documentation for more information.

abstract val isExternal: Boolean
JVM
1.1

isInfix

true if this function is infix. See the Kotlin language documentation for more information.

abstract val isInfix: Boolean
JVM
1.1

isInline

true if this function is inline. See the Kotlin language documentation for more information.

abstract val isInline: Boolean
JVM
1.1

isOperator

true if this function is operator. See the Kotlin language documentation for more information.

abstract val isOperator: Boolean
JVM
1.1

isSuspend

true if this is a suspending function.

abstract val isSuspend: Boolean

Inherited Properties

JVM
1.1

isAbstract

true if this callable is abstract.

abstract val isAbstract: Boolean
JVM
1.1

isFinal

true if this callable is final.

abstract val isFinal: Boolean
JVM
1.1

isOpen

true if this callable is open.

abstract val isOpen: Boolean
JVM
1.3

isSuspend

true if this is a suspending function.

abstract val isSuspend: Boolean
JVM
1.0

parameters

Parameters required to make a call to this callable. If this callable requires a this instance or an extension receiver parameter, they come first in the list in that order.

abstract val parameters: List<KParameter>
JVM
1.1

typeParameters

The list of type parameters of this callable.

abstract val typeParameters: List<KTypeParameter>
JVM
1.1

visibility

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

abstract val visibility: KVisibility?

Inherited Functions

JVM
1.0

call

Calls this callable with the specified list of arguments and returns the result. Throws an exception if the number of specified arguments is not equal to the size of parameters, or if their types do not match the types of the parameters.

abstract fun call(vararg args: Any?): R
JVM
1.0

callBy

Calls this callable with the specified mapping of parameters to arguments and returns the result. If a parameter is not found in the mapping and is not optional (as per KParameter.isOptional), or its type does not match the type of the provided value, an exception is thrown.

abstract fun callBy(args: Map<KParameter, Any?>): R

Extension Properties

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

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

isAccessible

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

var KCallable<*>.isAccessible: Boolean
JVM
1.0

javaConstructor

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.

val <T> KFunction<T>.javaConstructor: Constructor<T>?
JVM
1.0

javaMethod

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.

val KFunction<*>.javaMethod: Method?
JVM
1.1

valueParameters

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

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

Extension 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

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

hasAnnotation

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

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

reflect

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.

fun <R> Function<R>.reflect(): KFunction<R>?

Inheritors

JVM
1.0

Getter

Getter of the property is a get method declared alongside the property.

interface Getter<out V> : KProperty.Accessor<V>, KFunction<V>
JVM
1.0

Setter

Setter of the property is a set method declared alongside the property.

interface Setter<V> : KProperty.Accessor<V>, KFunction<Unit>