public class ReflectionUtils extends Object
Modifier and Type | Field | Description |
---|---|---|
static String |
JAVA_VERSION |
|
static boolean |
JAVA_VERSION_IS_8 |
|
static boolean |
JAVA_VERSION_IS_9_PLUS |
Constructor | Description |
---|---|
ReflectionUtils() |
Modifier and Type | Method | Description |
---|---|---|
static Class<?> |
classForNameOrNull(String className) |
Call Class.forName(className), but return null if any exception is thrown.
|
static Object |
getFieldVal(Object obj,
String fieldName,
boolean throwException) |
Get the value of the named field in the class of the given object or any of its superclasses.
|
static Object |
getStaticFieldVal(Class<?> cls,
String fieldName,
boolean throwException) |
Get the value of the named static field in the given class or any of its superclasses.
|
static Object |
invokeDefaultMethod(Class<?> cls,
String methodName,
Class<?> returnType,
ClassLoader classLoader,
boolean throwException) |
Invoke the named default interface method.
|
static Object |
invokeMethod(Object obj,
String methodName,
boolean throwException) |
Invoke the named method in the given object or its superclasses.
|
static Object |
invokeMethod(Object obj,
String methodName,
Class<?> argType,
Object arg,
boolean throwException) |
Invoke the named method in the given object or its superclasses.
|
static Object |
invokeStaticMethod(Class<?> cls,
String methodName,
boolean throwException) |
Invoke the named static method.
|
static Object |
invokeStaticMethod(Class<?> cls,
String methodName,
Class<?> argType,
Object arg,
boolean throwException) |
Invoke the named static method.
|
public static final String JAVA_VERSION
public static final boolean JAVA_VERSION_IS_8
public static final boolean JAVA_VERSION_IS_9_PLUS
public static Object getFieldVal(Object obj, String fieldName, boolean throwException) throws IllegalArgumentException, NullPointerException
public static Object getStaticFieldVal(Class<?> cls, String fieldName, boolean throwException) throws IllegalArgumentException, NullPointerException
public static Object invokeMethod(Object obj, String methodName, boolean throwException) throws IllegalArgumentException, NullPointerException
public static Object invokeMethod(Object obj, String methodName, Class<?> argType, Object arg, boolean throwException) throws IllegalArgumentException, NullPointerException
public static Object invokeStaticMethod(Class<?> cls, String methodName, boolean throwException) throws IllegalArgumentException, NullPointerException
public static Object invokeStaticMethod(Class<?> cls, String methodName, Class<?> argType, Object arg, boolean throwException) throws IllegalArgumentException, NullPointerException
public static Object invokeDefaultMethod(Class<?> cls, String methodName, Class<?> returnType, ClassLoader classLoader, boolean throwException) throws IllegalArgumentException, NullPointerException
Copyright © 2018. All rights reserved.