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

invokeGetterMethod

@Nullable open static fun invokeGetterMethod(target: Any, name: String): Any

Invoke the getter method with the given name on the supplied target object with the supplied value.

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 getter methods.

In addition, this method supports JavaBean-style property names. For example, if you wish to get the name property on the target object, you may pass either "name" or "getName" as the method name.

Parameters

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

name - the name of the getter method to invoke or the corresponding property name

Return
the value returned from the invocation

See Also
ReflectionUtils#findMethod(Class, String, Class[])ReflectionUtils#makeAccessible(Method)ReflectionUtils#invokeMethod(Method, Object, Object[])