public class ReflectUtil extends Object
| 限定符和类型 | 字段和说明 |
|---|---|
static java.util.function.Function<Class<?>,Field[]> |
CLASS_GET_ROOT_FIELDS |
static java.util.function.Function<Class<?>,Method[]> |
CLASS_GET_ROOT_METHODS |
static java.util.function.UnaryOperator<Field> |
FIELD_GET_ROOT |
static java.util.function.UnaryOperator<Method> |
METHOD_GET_ROOT |
| 构造器和说明 |
|---|
ReflectUtil() |
| 限定符和类型 | 方法和说明 |
|---|---|
static Field[] |
getAllFields(Class<?> clz,
boolean includeStatic)
Get both private and inherit fields
|
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) |
static Field |
getRootField(Field f)
Get root of the field.
|
static Field[] |
getRootFields(Class<?> clz)
Get root fields of the class.
|
static Method |
getRootMethod(Method m)
Get root of the method.
|
static Method[] |
getRootMethods(Class<?> clz)
Get root methods of the class.
|
public static final java.util.function.UnaryOperator<Method> METHOD_GET_ROOT
public static final java.util.function.Function<Class<?>,Method[]> CLASS_GET_ROOT_METHODS
public static final java.util.function.UnaryOperator<Field> FIELD_GET_ROOT
public static final java.util.function.Function<Class<?>,Field[]> CLASS_GET_ROOT_FIELDS
public static <T,O> O getFieldValue(Class<T> clz, T t, String fieldName) throws NoSuchFieldException
public static Field[] getAllFields(Class<?> clz, boolean includeStatic)
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 © 2017. All rights reserved.