Package org.apache.dubbo.common.utils
Class ReflectionUtils
java.lang.Object
org.apache.dubbo.common.utils.ReflectionUtils
A utility class that provides methods for accessing and manipulating private fields and methods of an object.
This is useful for white-box testing, where the internal workings of a class need to be tested directly.
Note: Usage of this class should be limited to testing purposes only, as it violates the encapsulation principle.
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptiongetClassGenerics(Class<?> clazz, Class<?> interfaceClass) Returns a list of distinctClassobjects representing the generics of the given class that implement the given interface.static ObjectRetrieves the value of the specified field from the given object.static ObjectInvokes the specified method on the given object with the provided parameters.static boolean
-
Method Details
-
getField
Retrieves the value of the specified field from the given object.- Parameters:
source- The object from which to retrieve the field value.fieldName- The name of the field to retrieve.- Returns:
- The value of the specified field in the given object.
- Throws:
RuntimeException- If the specified field does not exist.
-
invoke
Invokes the specified method on the given object with the provided parameters.- Parameters:
source- The object on which to invoke the method.methodName- The name of the method to invoke.params- The parameters to pass to the method.- Returns:
- The result of invoking the specified method on the given object.
-
getClassGenerics
Returns a list of distinctClassobjects representing the generics of the given class that implement the given interface.- Parameters:
clazz- the class to retrieve the generics forinterfaceClass- the interface to retrieve the generics for- Returns:
- a list of distinct
Classobjects representing the generics of the given class that implement the given interface
-
match
-