Closed
Description
Background
Spring Test's ReflectionTestUtils includes methods for setting/getting fields, like so (bolded text is from me):
getField(Class<?> targetClass, String name)
- Get the value of the static field with the given name from the provided
targetClass
.
- Get the value of the static field with the given name from the provided
getField(Object targetObject, Class<?> targetClass, String name)
- Get the value of the field with the given name from the provided
targetObject
/targetClass
.
- Get the value of the field with the given name from the provided
getField(Object targetObject, String name)
- Get the value of the field with the given name from the provided
targetObject
.
- Get the value of the field with the given name from the provided
Note that getField()
works for both static fields and regular fields (support for static fields was added in v4.2.0.RC1 with this commit, associated with #11458).
Problem
In contrast, there is only one version of invokeMethod()
, and it only works on an instantiated Object
.
invokeMethod(Object target, String name, Object... args)
- Invoke the method with the given name on the supplied target object with the supplied arguments.
There are no other versions of invokeMethod()
that work for static methods.
Feature Request
To make the class more consistent with getField()
and setField()
, I would like to request a new version of invokeMethod()
that works on static methods:
invokeMethod(Class<?> targetClass, String name, Object... args)
- Invoke the static method with the given name on the provided
targetClass
with the supplied arguments.
- Invoke the static method with the given name on the provided
If it makes sense, we should also add:
invokeMethod(Object targetObject, Class<?> targetClass, String name, Object... args)
- Invoke the method with the given name on the provided
targetObject
/targetClass
with the supplied arguments.
- Invoke the method with the given name on the provided