public class ReflectUtil extends Object
| 构造器和说明 |
|---|
ReflectUtil() |
| 限定符和类型 | 方法和说明 |
|---|---|
static Field[] |
getAllFields(Class<?> clz)
Get all fields
|
static Field[] |
getAllFields(Class<?> clz,
boolean includeStatic)
Get all fields
|
static Class<?>[] |
getAllInterfaces(Class<?> clz)
Get all interfaces
|
static Method[] |
getAllMethods(Class<?> clz)
Get all methods
|
static Class<?>[] |
getAllSuperClasses(Class<?> clz)
Get all super classes
|
static StackTraceElement |
getCaller() |
static StackTraceElement |
getCaller(int deep,
boolean ignoreSameClass)
Get caller stack info.
|
static String |
getCallerClassName()
Get the name of the class who calls the caller.
|
static <T,O> O |
getFieldValue(Class<T> clz,
T t,
String fieldName)
Get field value by name
|
static Type[] |
getGenericTypes(Type sourceType,
Class<?> targetClass)
已过时。
GenericUtil#getGenericTypes(Type, Class)
|
static <T extends Executable> |
getRootExecutable(T m)
Get root of the executable.
|
static Field |
getRootField(Field f)
Get root of the field.
|
static Field[] |
getRootFields(Class<?> clz)
Get root public fields of the class.
|
static Method |
getRootMethod(Method m)
Get root of the method.
|
static Method[] |
getRootMethods(Class<?> clz)
Get root public methods of the class.
|
static void |
setModifiers(AccessibleObject ao,
int modifier) |
public static void setModifiers(AccessibleObject ao, int modifier)
public static <T extends Executable> T getRootExecutable(T m)
public static Method[] getRootMethods(Class<?> clz)
public static Field[] getRootFields(Class<?> clz)
public static <T,O> O getFieldValue(Class<T> clz, T t, String fieldName) throws NoSuchFieldException
clz - t - fieldName - NoSuchFieldException@Deprecated public static Type[] getGenericTypes(Type sourceType, Class<?> targetClass)
sourceType - targetClass - public static Field[] getAllFields(Class<?> clz, boolean includeStatic)
clz - includeStatic - include static fields or notpublic static Class<?>[] getAllSuperClasses(Class<?> clz)
clz - public static Class<?>[] getAllInterfaces(Class<?> clz)
clz - public static String getCallerClassName()
class A {
static void fun() {
B.fun();
}
}
class B {
static void fun() {
System.out.println(ReflectUtil.getCallerClassName());
}
}
public static StackTraceElement getCaller()
public static StackTraceElement getCaller(int deep, boolean ignoreSameClass)
deep - Deep to search the caller class.If deep is 0, it returns the class who calls this method.ignoreSameClass - If it is true, calling in same class will be ignored.Copyright © 2018. All rights reserved.