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

ReflectiveMethod

public 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(
    @NonNull String className,
    @NonNull String methodName,
    @NonNull Array<@NonNull Class<@NonNull Object>> paramTypes
)

Creates a ReflectiveMethod.

Public methods

@NonNull T
invoke(@NonNull Object object, @NonNull Array<@NonNull Object> paramValues)

Invoke the instance method.

@NonNull T

Invoke th static method.

Public constructors

ReflectiveMethod

public ReflectiveMethod(
    @NonNull String className,
    @NonNull String methodName,
    @NonNull Array<@NonNull Class<@NonNull Object>> paramTypes
)

Creates a ReflectiveMethod.

Parameters
@NonNull String className

the fully qualified class name that defines the method

@NonNull String methodName

the method name to call

@NonNull Array<@NonNull Class<@NonNull Object>> paramTypes

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

Public methods

invoke

@NonNull
public T invoke(@NonNull Object object, @NonNull Array<@NonNull Object> paramValues)

Invoke the instance method.

See invoke

Parameters
@NonNull Object object

the object the underlying method is invoked from

@NonNull Array<@NonNull Object> paramValues

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

@NonNull
public T invokeStatic(@NonNull Array<@NonNull Object> paramValues)

Invoke th static method.

See invoke

Parameters
@NonNull Array<@NonNull Object> paramValues

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