spring-framework / org.springframework.test.util / ReflectionTestUtils / invokeMethod

invokeMethod

@Nullable open static fun <T : Any> invokeMethod(target: Any, name: String, vararg args: Any): T

Invoke the method with the given name on the supplied target object with the supplied arguments.

This method traverses the class hierarchy in search of the desired method. In addition, an attempt will be made to make non-public methods accessible, thus allowing one to invoke protected, private, and package-private methods.

Parameters

target - the target object on which to invoke the specified method

name - the name of the method to invoke

args - the arguments to provide to the method

Return
the invocation result, if any

See Also
MethodInvokerReflectionUtils#makeAccessible(Method)ReflectionUtils#invokeMethod(Method, Object, Object[])ReflectionUtils#handleReflectionException(Exception)