反射工具类

类名: ReflectUtil

getBeanGetters

/**
* 获取 Bean 的所有 get方法
*
* @param type 类
* @return PropertyDescriptor数组
*/
ReflectUtil.getBeanGetters(Class type);

getBeanSetters

/**
* 获取 Bean 的所有 set方法
*
* @param type 类
* @return PropertyDescriptor数组
*/
ReflectUtil.getBeanSetters(Class type);

getPropertyDescriptors

/**
* 获取 Bean 的所有 PropertyDescriptor
*
* @param type 类
* @param read 读取方法
* @param write 写方法
* @return PropertyDescriptor数组
*/
ReflectUtil.getPropertyDescriptors(Class type, boolean read, boolean write);

getProperty

/**
* 获取 bean 的属性信息
*
* @param propertyType 类型
* @param propertyName 属性名
* @return {Property}
*/
ReflectUtil.getProperty(Class<?> propertyType, String propertyName);

getProperty

/**
* 获取 bean 的属性信息
*
* @param propertyType 类型
* @param propertyDescriptor PropertyDescriptor
* @param propertyName 属性名
* @return {Property}
*/
ReflectUtil.getProperty(Class<?> propertyType, PropertyDescriptor propertyDescriptor, String propertyName);

getTypeDescriptor

/**
* 获取 bean 的属性信息
*
* @param propertyType 类型
* @param propertyName 属性名
* @return {Property}
*/
ReflectUtil.getTypeDescriptor(Class<?> propertyType, String propertyName);

getTypeDescriptor

/**
* 获取 类属性信息
*
* @param propertyType 类型
* @param propertyDescriptor PropertyDescriptor
* @param propertyName 属性名
* @return {Property}
*/
ReflectUtil.getTypeDescriptor(Class<?> propertyType, PropertyDescriptor propertyDescriptor, String propertyName);

getField

/**
* 获取 类属性
*
* @param clazz 类信息
* @param fieldName 属性名
* @return Field
*/
ReflectUtil.getField(Class<?> clazz, String fieldName);

getAnnotation

/**
* 获取 所有 field 属性上的注解
*
* @param clazz 类
* @param fieldName 属性名
* @param annotationClass 注解
* @param <T> 注解泛型
* @return 注解
*/
ReflectUtil.getAnnotation(Class<?> clazz, String fieldName, Class<T> annotationClass);

setField

/**
* 重写 setField 的方法,用于处理 setAccessible 的问题
*
* @param field Field
* @param target Object
* @param value value
*/
ReflectUtil.setField(Field field, Object target, Object value);

getField

/**
* 重写 setField 的方法,用于处理 setAccessible 的问题
*
* @param field Field
* @param target Object
* @return value
*/
ReflectUtil.getField(Field field, Object target);

invokeMethod

/**
* 重写 invokeMethod 的方法,用于处理 setAccessible 的问题
*
* @param method Method
* @param target Object
* @return value
*/
ReflectUtil.invokeMethod(Method method, Object target);

invokeMethod

/**
* 重写 invokeMethod 的方法,用于处理 setAccessible 的问题
*
* @param method Method
* @param target Object
* @param args args
* @return value
*/
ReflectUtil.invokeMethod(Method method, Object target, Object args);

微信 vs 公众号

如梦技术

精彩内容每日推荐!!!