Interface PropertyAccessor<T>

Type Parameters:
T - the target type | 目标类型
All Known Implementing Classes:
BeanAccessor, FieldAccessor, LambdaAccessor, MethodHandleAccessor, VarHandleAccessor

public interface PropertyAccessor<T>
Property Accessor Interface 属性访问器接口

Unified interface for property read/write operations.

属性读写操作的统一接口。

Features | 主要功能:

  • Property read/write operations - 属性读写操作
  • Type and generic type access - 类型和泛型类型访问
  • Readability/writability checking - 可读/可写检查

Usage Examples | 使用示例:

PropertyAccessor<User> accessor = PropertyAccessors.create(User.class, "name");
Object value = accessor.get(user);
accessor.set(user, "Alice");

Security | 安全性:

  • Thread-safe: Depends on implementation - 线程安全: 取决于实现
  • Null-safe: No (caller must ensure non-null target) - 空值安全: 否(调用方须确保非空目标)
Since:
JDK 25, opencode-base-reflect V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    get(T target)
    Gets the property value 获取属性值
    default <V> V
    get(T target, Class<V> type)
    Gets the property value with type 获取属性值(带类型)
    Gets the declaring class 获取声明类
    Gets the generic property type 获取泛型属性类型
    Gets the property name 获取属性名
    default <V> V
    getOrDefault(T target, V defaultValue)
    Gets property value or default 获取属性值或默认值
    Gets the property type 获取属性类型
    boolean
    Checks if property is readable 检查属性是否可读
    boolean
    Checks if property is writable 检查属性是否可写
    void
    set(T target, Object value)
    Sets the property value 设置属性值
    default boolean
    setIfWritable(T target, Object value)
    Sets the property value if writable 如果可写则设置属性值
  • Method Details

    • getName

      String getName()
      Gets the property name 获取属性名
      Returns:
      the property name | 属性名
    • getType

      Class<?> getType()
      Gets the property type 获取属性类型
      Returns:
      the property type | 属性类型
    • getGenericType

      Type getGenericType()
      Gets the generic property type 获取泛型属性类型
      Returns:
      the generic type | 泛型类型
    • getDeclaringClass

      Class<T> getDeclaringClass()
      Gets the declaring class 获取声明类
      Returns:
      the declaring class | 声明类
    • isReadable

      boolean isReadable()
      Checks if property is readable 检查属性是否可读
      Returns:
      true if readable | 如果可读返回true
    • isWritable

      boolean isWritable()
      Checks if property is writable 检查属性是否可写
      Returns:
      true if writable | 如果可写返回true
    • get

      Object get(T target)
      Gets the property value 获取属性值
      Parameters:
      target - the target object | 目标对象
      Returns:
      the value | 值
      Throws:
      IllegalStateException - if not readable | 如果不可读
    • get

      default <V> V get(T target, Class<V> type)
      Gets the property value with type 获取属性值(带类型)
      Type Parameters:
      V - the value type | 值类型
      Parameters:
      target - the target object | 目标对象
      type - the expected type | 期望类型
      Returns:
      the value | 值
    • set

      void set(T target, Object value)
      Sets the property value 设置属性值
      Parameters:
      target - the target object | 目标对象
      value - the value | 值
      Throws:
      IllegalStateException - if not writable | 如果不可写
    • setIfWritable

      default boolean setIfWritable(T target, Object value)
      Sets the property value if writable 如果可写则设置属性值
      Parameters:
      target - the target object | 目标对象
      value - the value | 值
      Returns:
      true if set | 如果已设置返回true
    • getOrDefault

      default <V> V getOrDefault(T target, V defaultValue)
      Gets property value or default 获取属性值或默认值
      Type Parameters:
      V - the value type | 值类型
      Parameters:
      target - the target object | 目标对象
      defaultValue - the default value | 默认值
      Returns:
      the value or default | 值或默认值