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

invokeSetterMethod

open static fun invokeSetterMethod(target: Any, name: String, value: Any): Unit

Invoke the setter 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 setter methods.

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

Parameters

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

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

value - the value to provide to the setter method

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

open static fun invokeSetterMethod(target: Any, name: String, @Nullable value: Any, @Nullable type: Class<*>): Unit

Invoke the setter 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 setter methods.

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

Parameters

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

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

value - the value to provide to the setter method

type - the formal parameter type declared by the setter method

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