Class OpenField
java.lang.Object
cloud.opencode.base.reflect.OpenField
Field Facade Entry Class
字段门面入口类
Provides common field operations API, internally delegates to FieldUtil. Similar to Commons Lang FieldUtils.
提供常用字段操作API,内部委托给FieldUtil。 对标Commons Lang FieldUtils。
Features | 主要功能:
- Field retrieval (with inheritance) - 字段获取(含继承)
- Field read/write operations - 字段读写操作
- Batch field operations - 批量字段操作
- Annotation-based filtering - 基于注解的过滤
Usage Examples | 使用示例:
// Read field value
Object value = OpenField.readField(obj, "name");
// Write field value
OpenField.writeField(obj, "name", "newValue");
// Get all fields with annotation
List<Field> fields = OpenField.getFieldsWithAnnotation(User.class, Column.class);
Security | 安全性:
- Thread-safe: Yes (stateless utility class) - 线程安全: 是(无状态工具类)
- Null-safe: No (caller must ensure non-null arguments) - 空值安全: 否(调用方须确保非空参数)
- Since:
- JDK 25, opencode-base-reflect V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionFinds first matching field 查找第一个匹配字段static voidIterates all fields (including inherited) 遍历所有字段(含继承)getAllFields(Class<?> clazz) Gets all fields (including inherited) 获取所有字段(包含继承)static FieldgetDeclaredField(Class<?> clazz, String fieldName) Gets a declared field (not inherited) 获取声明的字段(不含继承)getDeclaredFields(Class<?> clazz) Gets declared fields (not inherited) 获取声明的字段(不含继承)static FieldGets a field (including inherited) 获取字段(包含继承)static FieldGets a field with optional force access 获取字段(可选强制访问)static TypegetFieldGenericType(Class<?> clazz, String fieldName) Gets field generic type 获取字段泛型类型getFieldsOfType(Class<?> clazz, Class<?> fieldType) Gets fields of specific type 按类型获取字段getFieldsWithAnnotation(Class<?> clazz, Class<? extends Annotation> annotationClass) Gets fields with specific annotation 按注解获取字段getFieldsWithModifiers(Class<?> clazz, int... modifiers) Gets fields with specific modifiers 按修饰符获取字段static Class<?> getFieldType(Class<?> clazz, String fieldName) Gets field type 获取字段类型static TypeToken<?> getFieldTypeToken(Class<?> clazz, String fieldName) Gets field TypeToken 获取字段TypeTokenstatic booleanChecks if field exists 检查字段是否存在static ObjectReads field value 读取字段值static ObjectReads field value with optional force access 读取字段值(可选强制访问)static <T> TReads field value with type safety 读取字段值(泛型安全)static ObjectReads field value using Field object 读取字段值(Field对象)readFields(Object target, String... fieldNames) Reads specific fields 批量读取指定字段readFieldsToMap(Object target) Reads all fields to Map 批量读取为Mapstatic ObjectreadStaticField(Class<?> clazz, String fieldName) Reads static field 读取静态字段static <T> TreadStaticField(Class<?> clazz, String fieldName, Class<T> valueType) Reads static field with type safety 读取静态字段(泛型安全)static voidremoveFinalAndWrite(Object target, String fieldName, Object value) Removes final modifier and writes value 移除final修饰符并写入值Creates a field stream 创建字段流static voidwriteField(Object target, String fieldName, Object value) Writes field value 写入字段值static voidwriteField(Object target, String fieldName, Object value, boolean forceAccess) Writes field value with optional force access 写入字段值(可选强制访问)static voidwriteField(Field field, Object target, Object value) Writes field value using Field object 写入字段值(Field对象)static voidwriteFieldsFromMap(Object target, Map<String, Object> values) Writes fields from Map 从Map批量写入static voidwriteStaticField(Class<?> clazz, String fieldName, Object value) Writes static field 写入静态字段
-
Method Details
-
getField
Gets a field (including inherited) 获取字段(包含继承)- Parameters:
clazz- the class | 类fieldName- the field name | 字段名- Returns:
- the field | 字段
- Throws:
OpenReflectException- if not found | 如果未找到
-
getField
Gets a field with optional force access 获取字段(可选强制访问)- Parameters:
clazz- the class | 类fieldName- the field name | 字段名forceAccess- whether to force access | 是否强制访问- Returns:
- the field | 字段
- Throws:
OpenReflectException- if not found | 如果未找到
-
getDeclaredField
Gets a declared field (not inherited) 获取声明的字段(不含继承)- Parameters:
clazz- the class | 类fieldName- the field name | 字段名- Returns:
- the field | 字段
- Throws:
OpenReflectException- if not found | 如果未找到
-
getAllFields
-
getDeclaredFields
-
getFieldsWithAnnotation
public static List<Field> getFieldsWithAnnotation(Class<?> clazz, Class<? extends Annotation> annotationClass) Gets fields with specific annotation 按注解获取字段- Parameters:
clazz- the class | 类annotationClass- the annotation class | 注解类- Returns:
- list of fields | 字段列表
-
getFieldsOfType
-
getFieldsWithModifiers
-
readField
-
readField
-
readField
-
readField
Reads field value with type safety 读取字段值(泛型安全)- Type Parameters:
T- the value type | 值类型- Parameters:
target- the target object | 目标对象fieldName- the field name | 字段名valueType- the expected type | 期望类型- Returns:
- the value | 值
-
readStaticField
-
readStaticField
Reads static field with type safety 读取静态字段(泛型安全)- Type Parameters:
T- the value type | 值类型- Parameters:
clazz- the class | 类fieldName- the field name | 字段名valueType- the expected type | 期望类型- Returns:
- the value | 值
-
writeField
-
writeField
Writes field value with optional force access 写入字段值(可选强制访问)- Parameters:
target- the target object | 目标对象fieldName- the field name | 字段名value- the value | 值forceAccess- whether to force access | 是否强制访问
-
writeField
-
writeStaticField
-
removeFinalAndWrite
-
getFieldType
-
getFieldGenericType
-
getFieldTypeToken
-
hasField
-
forEach
-
findFirst
-
stream
-
readFieldsToMap
-
readFields
-
writeFieldsFromMap
-