public abstract class ReflectionOpt extends Object
| 限定符和类型 | 字段和说明 |
|---|---|
protected static org.slf4j.Logger |
logger |
| 限定符和类型 | 方法和说明 |
|---|---|
static Object |
attainExpressionValue(Object sourceObj,
String expression)
获得 对象的 属性; 目前只能支持一维数组的获取,多维数据暂时不支持,目前看也没有这个需要
|
<T> T |
createObjectFromMap(Class<T> clazz,
Map<String,Object> properties) |
static Object |
forceGetFieldValue(Object object,
Field field) |
static Object |
forceGetProperty(Object object,
String propertyName) |
static void |
forceSetProperty(Object object,
String propertyName,
Object newValue) |
static List<Method> |
getAllGetterMethod(Class<?> type) |
static List<Method> |
getAllSetterMethod(Class<?> type) |
static Boolean |
getBooleanFieldValue(Object obj,
String fieldName) |
static Method |
getBooleanGetterMethod(Class<?> classType,
String fieldName) |
static String |
getCurrentMethodName() |
static Field |
getDeclaredField(Class<?> clazz,
String propertyName) |
static Field |
getDeclaredField(Object object,
String propertyName) |
static Field[] |
getFields(Object object) |
static List<Field> |
getFieldsByType(Object object,
Class<?> type) |
static Object |
getFieldValue(Object obj,
Field field) |
static Object |
getFieldValue(Object obj,
String fieldName) |
static Method |
getGetterMethod(Class<?> classType,
Class<?> propertyType,
String fieldName) |
static Method |
getGetterMethod(Class<?> classType,
String fieldName) |
static String |
getJavaTypeName(Class<?> type) |
static LeftRightPair<Method,Object[]> |
getMatchBestMethod(Class<?> classType,
String methodName,
Map<String,Object> params) |
static Class<?> |
getPropertyType(Class<?> type,
String name) |
static Method |
getSetterMethod(Class<?> classType,
Class<?> propertyType,
String fieldName) |
static Class<?> |
getSuperClassGenricType(Class<?> clazz) |
static Class<?> |
getSuperClassGenricType(Class<?> clazz,
int index) |
static <T> Object |
invokeBinaryOpt(T demander,
String smethod,
T param) |
static Object |
invokeMethod(Object demander,
String smethod,
Object... params) |
static Object |
invokeNoParamFunc(Object demander,
String smethod) |
static Object |
invokePrivateMethod(Object object,
String methodName,
Object... params) |
static boolean |
isArray(Object obj)
判断一个对象是否是 数组[]、Collection(List)
|
static boolean |
isArrayType(Class<?> tp)
判断一个类型是否是 数组[]、Collection(List)
|
static boolean |
isNumberType(Class<?> tp) |
static boolean |
isPrimitiveType(Class<?> tp)
isPrimitiveType
判断一个类型是否是基础类型 int boolean void float double char
或者单值类型 String Date Integer Float Double, scalar
|
static boolean |
isScalarType(Class<?> tp)
isScalarType
判断一个类型是否是基础类型 int boolean void float double char
或者单值类型 String Date Integer Float Double, scalar
|
static String |
mapGetter2Field(Method method)
将getter方法映射为对应属性
|
static String |
methodNameToField(String methodName) |
static boolean |
setAttributeValue(Object object,
String attributeName,
Object newValue) |
static boolean |
setFieldValue(Object object,
String fieldName,
Object newValue) |
static boolean |
setFieldValue(Object object,
String fieldName,
Object newValue,
Class<?> paramType) |
public static Field getDeclaredField(Object object, String propertyName) throws NoSuchFieldException
public static Field getDeclaredField(Class<?> clazz, String propertyName) throws NoSuchFieldException
public static boolean setFieldValue(Object object, String fieldName, Object newValue, Class<?> paramType)
public static boolean setAttributeValue(Object object, String attributeName, Object newValue)
public static Object forceGetProperty(Object object, String propertyName) throws NoSuchFieldException
public static void forceSetProperty(Object object, String propertyName, Object newValue) throws NoSuchFieldException
public static Class<?> getPropertyType(Class<?> type, String name) throws NoSuchFieldException
public static Method getGetterMethod(Class<?> classType, Class<?> propertyType, String fieldName)
public static Method getSetterMethod(Class<?> classType, Class<?> propertyType, String fieldName)
public static LeftRightPair<Method,Object[]> getMatchBestMethod(Class<?> classType, String methodName, Map<String,Object> params)
public static Object attainExpressionValue(Object sourceObj, String expression)
sourceObj - 可以是 任意对象expression - 表达式 a.b.[1].c 也可以 a.b.[1].[2].c 间接实现二维数组
这个地方没有引入词法分析器,是用"."来分割的,每一段可以理解为一个操作
如果是一个字符串就是找对应的属性,如果是"[数字]"就是针对数组找对应的元素public static Method getBooleanGetterMethod(Class<?> classType, String fieldName)
public static String mapGetter2Field(Method method)
method - Getter方法public static Object invokePrivateMethod(Object object, String methodName, Object... params) throws NoSuchMethodException
public static Class<?> getSuperClassGenricType(Class<?> clazz)
clazz - The class to introspectObject.class if cannot be determinedpublic static Class<?> getSuperClassGenricType(Class<?> clazz, int index)
clazz - clazz The class to introspectindex - the Index of the generic declaration,start from 0.Object.class if
cannot be determinedpublic static boolean isPrimitiveType(Class<?> tp)
tp - isPrimitiveTypepublic static boolean isScalarType(Class<?> tp)
tp - isScalarTypepublic static boolean isNumberType(Class<?> tp)
public static boolean isArray(Object obj)
obj - 对象public static boolean isArrayType(Class<?> tp)
tp - 类型public static String getCurrentMethodName()
public <T> T createObjectFromMap(Class<T> clazz, Map<String,Object> properties) throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException
Copyright © 2025 江苏南大先腾信息产业股份有限公司. All rights reserved.