public final class ReflectionUtils
extends java.lang.Object
| Modifier and Type | Field and Description |
|---|---|
static nonapi.io.github.classgraph.reflection.ReflectionDriver |
reflectionDriver
The reflection driver to use.
|
| Modifier and Type | Method and Description |
|---|---|
static java.lang.Class<?> |
classForNameOrNull(java.lang.String className)
Call Class.forName(className), but return null if any exception is thrown.
|
static <T> T |
doPrivileged(java.util.concurrent.Callable<T> callable)
Call a method in the AccessController.doPrivileged(PrivilegedAction) context, using reflection, if possible
(AccessController is deprecated in JDK 17).
|
static java.lang.Object |
getFieldVal(boolean throwException,
java.lang.Object obj,
java.lang.reflect.Field field)
Get the value of the field in the class of the given object or any of its superclasses.
|
static java.lang.Object |
getFieldVal(boolean throwException,
java.lang.Object obj,
java.lang.String fieldName)
Get the value of the named field in the class of the given object or any of its superclasses.
|
static java.lang.Object |
getStaticFieldVal(boolean throwException,
java.lang.Class<?> cls,
java.lang.String fieldName)
Get the value of the named static field in the given class or any of its superclasses.
|
static java.lang.Object |
invokeMethod(boolean throwException,
java.lang.Object obj,
java.lang.String methodName)
Invoke the named method in the given object or its superclasses.
|
static java.lang.Object |
invokeMethod(boolean throwException,
java.lang.Object obj,
java.lang.String methodName,
java.lang.Class<?> argType,
java.lang.Object param)
Invoke the named method in the given object or its superclasses.
|
static java.lang.Object |
invokeStaticMethod(boolean throwException,
java.lang.Class<?> cls,
java.lang.String methodName)
Invoke the named static method.
|
static java.lang.Object |
invokeStaticMethod(boolean throwException,
java.lang.Class<?> cls,
java.lang.String methodName,
java.lang.Class<?> argType,
java.lang.Object param)
Invoke the named static method.
|
static void |
loadReflectionDriver()
Call this if you change the value of
ClassGraph.CIRCUMVENT_ENCAPSULATION. |
public static nonapi.io.github.classgraph.reflection.ReflectionDriver reflectionDriver
public static void loadReflectionDriver()
ClassGraph.CIRCUMVENT_ENCAPSULATION.public static java.lang.Object getFieldVal(boolean throwException,
java.lang.Object obj,
java.lang.reflect.Field field)
throws java.lang.IllegalArgumentException
throwException - If true, throw an exception if the field value could not be read.obj - The object.field - The field.java.lang.IllegalArgumentException - If the field value could not be read.public static java.lang.Object getFieldVal(boolean throwException,
java.lang.Object obj,
java.lang.String fieldName)
throws java.lang.IllegalArgumentException
throwException - If true, throw an exception if the field value could not be read.obj - The object.fieldName - The field name.java.lang.IllegalArgumentException - If the field value could not be read.public static java.lang.Object getStaticFieldVal(boolean throwException,
java.lang.Class<?> cls,
java.lang.String fieldName)
throws java.lang.IllegalArgumentException
throwException - If true, throw an exception if the field value could not be read.cls - The class.fieldName - The field name.java.lang.IllegalArgumentException - If the field value could not be read.public static java.lang.Object invokeMethod(boolean throwException,
java.lang.Object obj,
java.lang.String methodName)
throws java.lang.IllegalArgumentException
throwException - If true, throw an exception if the field value could not be read.obj - The object.methodName - The method name.java.lang.IllegalArgumentException - If the method could not be invoked.public static java.lang.Object invokeMethod(boolean throwException,
java.lang.Object obj,
java.lang.String methodName,
java.lang.Class<?> argType,
java.lang.Object param)
throws java.lang.IllegalArgumentException
throwException - Whether to throw an exception on failure.obj - The object.methodName - The method name.argType - The type of the method argument.param - The parameter value to use when invoking the method.java.lang.IllegalArgumentException - If the method could not be invoked.public static java.lang.Object invokeStaticMethod(boolean throwException,
java.lang.Class<?> cls,
java.lang.String methodName)
throws java.lang.IllegalArgumentException
throwException - Whether to throw an exception on failure.cls - The class.methodName - The method name.java.lang.IllegalArgumentException - If the method could not be invoked.public static java.lang.Object invokeStaticMethod(boolean throwException,
java.lang.Class<?> cls,
java.lang.String methodName,
java.lang.Class<?> argType,
java.lang.Object param)
throws java.lang.IllegalArgumentException
throwException - Whether to throw an exception on failure.cls - The class.methodName - The method name.argType - The type of the method argument.param - The parameter value to use when invoking the method.java.lang.IllegalArgumentException - If the method could not be invoked.public static java.lang.Class<?> classForNameOrNull(java.lang.String className)
className - The class name to load.public static <T> T doPrivileged(java.util.concurrent.Callable<T> callable)
throws java.lang.Throwable
java.lang.Throwable