public final class ReflectionUtils
extends Object
| Modifier and Type | Method and Description |
|---|---|
static Method |
retrieveMethod(Class<?> clazz,
String name,
Class<?>... parameterTypes)
Retrieves the specific
Method from the Class without checked exception. |
static Throwable |
trySetAccessible(AccessibleObject object,
boolean checkAccessible)
Try to call
AccessibleObject.setAccessible(boolean) but will catch any SecurityException and
java.lang.reflect.InaccessibleObjectException (for JDK 9) and return it. |
public static Method retrieveMethod(Class<?> clazz,
String name,
Class<?>... parameterTypes)
Method from the Class without checked exception.
Throws IllegalArgumentException if NoSuchMethodException is thrown.
clazz - Class to retrieve a Method fromname - the name of the methodparameterTypes - the list of method parametersMethod object@Nullable
public static Throwable trySetAccessible(AccessibleObject object,
boolean checkAccessible)
AccessibleObject.setAccessible(boolean) but will catch any SecurityException and
java.lang.reflect.InaccessibleObjectException (for JDK 9) and return it.
The caller must check if it returns null and if not handle the returned exception.object - The object to attempt to make accessible.checkAccessible - true to respect system property configuration which may limit
AccessibleObject.setAccessible(boolean) attempts. false to try regardless of system property
configuration.Throwable indicating the exception that occurred while attempting to make object
accessible, or null if the operation was successful.