Class FieldUtil
java.lang.Object
cloud.opencode.base.core.reflect.FieldUtil
Field Utility Class - Field reflection operations
字段工具类 - 字段反射操作
Provides utilities for field discovery, filtering, and access operations.
提供字段发现、过滤和访问操作工具。
Features | 主要功能:
- Get all/declared fields (with inheritance) - 获取全部/声明字段(含继承)
- Filter by annotation, type, modifier - 按注解、类型、修饰符过滤
- Field value get/set operations - 字段值读写操作
- Modifier checks (static, final, transient) - 修饰符检查
Usage Examples | 使用示例:
// Get all fields - 获取所有字段
List<Field> fields = FieldUtil.getAllFields(User.class);
// Get by annotation - 按注解获取
List<Field> annotated = FieldUtil.getFieldsWithAnnotation(User.class, Column.class);
// Get/Set value - 读写值
Object value = FieldUtil.getValue(user, field);
FieldUtil.setValue(user, field, newValue);
Security | 安全性:
- Thread-safe: Yes (stateless) - 线程安全: 是 (无状态)
- Null-safe: No - 空值安全: 否
Performance | 性能特性:
- Time complexity: O(n) where n = declared fields - O(n), n为声明的字段数
- Space complexity: O(1) per access - 每次访问 O(1)
- Since:
- JDK 25, opencode-base-core V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptiongetAllFields(Class<?> clazz) Gets all fields (including superclass) 获取所有字段(包括父类)getDeclaredFields(Class<?> clazz) Gets declared fields (excluding superclass) 获取声明的字段(不包括父类)getFieldByName(Class<?> clazz, String name) Gets a field by name 按名称获取字段getFieldMap(Class<?> clazz) Creates a field name to field mapping 创建字段名到字段的映射getFieldNames(Class<?> clazz) Gets the list of field names 获取字段名列表getFieldsByType(Class<?> clazz, Class<?> fieldType) Gets fields of the specified type 获取指定类型的字段getFieldsWithAnnotation(Class<?> clazz, Class<? extends Annotation> annotation) Gets fields with the specified annotation 获取带有指定注解的字段static TypegetGenericType(Field field) Gets the generic type of a field 获取字段的泛型类型getInstanceFields(Class<?> clazz) Gets instance fields (non-static) 获取实例字段(非静态)getPublicFields(Class<?> clazz) Gets public fields 获取公共字段getStaticFields(Class<?> clazz) Gets static fields 获取静态字段static <T> TGets the field value 获取字段值static booleanChecks if the field is final 检查字段是否为 finalstatic booleanChecks if the field is static 检查字段是否为 staticstatic booleanisTransient(Field field) Checks if the field is transient 检查字段是否为 transientstatic booleanisVolatile(Field field) Checks if the field is volatile 检查字段是否为 volatilestatic voidSets the field value 设置字段值
-
Method Details
-
getAllFields
-
getDeclaredFields
-
getFieldByName
-
getFieldsWithAnnotation
public static List<Field> getFieldsWithAnnotation(Class<?> clazz, Class<? extends Annotation> annotation) Gets fields with the specified annotation 获取带有指定注解的字段 -
getFieldsByType
-
getStaticFields
-
getInstanceFields
-
getPublicFields
-
getGenericType
-
getValue
-
setValue
-
isFinal
Checks if the field is final 检查字段是否为 final -
isStatic
Checks if the field is static 检查字段是否为 static -
isTransient
Checks if the field is transient 检查字段是否为 transient -
isVolatile
Checks if the field is volatile 检查字段是否为 volatile -
getFieldNames
-
getFieldMap
-