public final class ReflectFieldUtil extends Object
| 限定符和类型 | 方法和说明 |
|---|---|
static boolean |
containsAnnotationField(Class clazz,
Class<? extends Annotation> annotationClass)
当前类包含指定的注解信息
|
static Class |
getComponentType(Field field)
获取字段的类型
|
static Class |
getComponentType(Field field,
int typeIndex)
获取字段的类型
主要作用于集合类型
String[] 返回 String
Collection<String> 返回 String
Map<String, Integer> 返回 0: String, 1: Integer
|
static Field |
getField(Class clazz,
String fieldName)
获取指定字段名称的字段信息
|
static Field |
getField(Object object,
String fieldName)
获取指定字段名称的字段信息
|
static Class |
getGenericParamType(Field field,
int paramIndex)
获取字段的泛型参数类型
[java通过反射获取List中的泛型](https://blog.csdn.net/yy19900811/article/details/24239945?
|
static Object |
getValue(Field field,
Object instance)
获取对应的值信息
|
static Object |
getValue(String fieldName,
Object instance)
获取对应的值信息
|
static boolean |
isAnnotationPresent(Field field,
Class<? extends Annotation> clazz)
判断字段field,声明了clazz注解
|
static boolean |
isAssignable(Field sourceField,
Field targetField)
是否可以设置
|
static boolean |
isNotAnnotationPresent(Field field,
Class<? extends Annotation> clazz)
判断字段field,未声明clazz注解
|
static Boolean |
isNotString(Field field)
判断字段是否不为字符串类型
|
static Boolean |
isString(Field field)
判断字段为字符串类型
|
static void |
setValue(Field field,
Object instance,
Object fieldValue)
设置字段的值
|
static void |
setValue(Object instance,
String fieldName,
Object fieldValue)
设置字段值
|
public static boolean isAssignable(Field sourceField, Field targetField)
sourceField - 原始字段targetField - 目标字段public static boolean isAnnotationPresent(Field field, Class<? extends Annotation> clazz)
field - 字段clazz - 注解public static boolean isNotAnnotationPresent(Field field, Class<? extends Annotation> clazz)
field - 字段clazz - 注解public static Class getGenericParamType(Field field, int paramIndex)
field - 字段paramIndex - 泛型参数的下标public static boolean containsAnnotationField(Class clazz, Class<? extends Annotation> annotationClass)
clazz - 类annotationClass - 注解类public static Class getComponentType(Field field, int typeIndex)
String[] 返回 String Collection<String> 返回 String Map<String, Integer> 返回 0: String, 1: Integer
field - 集合类型的字段typeIndex - 类型的下标public static Class getComponentType(Field field)
field - 集合类型的字段public static void setValue(Field field, Object instance, Object fieldValue)
field - 字段instance - 实例对象fieldValue - 值设置对象public static void setValue(Object instance, String fieldName, Object fieldValue)
instance - 实例fieldName - 字段名称fieldValue - 字段值public static Object getValue(Field field, Object instance)
field - 字段instance - 实例public static Object getValue(String fieldName, Object instance)
fieldName - 字段名称instance - 实例public static Field getField(Object object, String fieldName)
object - 对象实例fieldName - 字段名称Copyright © 2024. All rights reserved.