{% setvar book_path %}/reference/kotlin/androidx/_book.yaml{% endsetvar %} {% include "_shared/_reference-head-tags.html" %}

ReflectiveMethod

class ReflectiveMethod<T>


Helper class for making more performant reflection method invocations.

Lazy initializes and caches Method object to attempt to reduce reflection overhead.

Summary

Public constructors

ReflectiveMethod(
    className: String,
    methodName: String,
    paramTypes: Array<Class<Any>>
)

Creates a ReflectiveMethod.

Public functions

T
invoke(object: Any, paramValues: Array<Any>)

Invoke the instance method.

T
invokeStatic(paramValues: Array<Any>)

Invoke th static method.

Public constructors

ReflectiveMethod

ReflectiveMethod(
    className: String,
    methodName: String,
    paramTypes: Array<Class<Any>>
)

Creates a ReflectiveMethod.

Parameters
className: String

the fully qualified class name that defines the method

methodName: String

the method name to call

paramTypes: Array<Class<Any>>

the list of types of the method parameters, in order.

Public functions

invoke

fun invoke(object: Any, paramValues: Array<Any>): T

Invoke the instance method.

See invoke

Parameters
object: Any

the object the underlying method is invoked from

paramValues: Array<Any>

the arguments used for the method call

Returns
T

the return value of the method

Throws
androidx.test.platform.reflect.ReflectionException

if call could not be completed

invokeStatic

fun invokeStatic(paramValues: Array<Any>): T

Invoke th static method.

See invoke

Parameters
paramValues: Array<Any>

the arguments used for the method call

Returns
T

the return value of the method

Throws
androidx.test.platform.reflect.ReflectionException

if call could not be completed