Class PropertyDescriptor

java.lang.Object
cloud.opencode.base.reflect.bean.PropertyDescriptor

public class PropertyDescriptor extends Object
Property Descriptor 属性描述符

Describes a bean property with its getter, setter, and field.

描述bean属性及其getter、setter和字段。

Features | 主要功能:

  • Getter/setter/field access - getter/setter/字段访问
  • Property readability/writability checking - 属性可读/可写检查
  • Annotation access on property - 属性上的注解访问

Usage Examples | 使用示例:

PropertyDescriptor desc = OpenBean.getPropertyDescriptors(User.class).get("name");
Object value = desc.getValue(user);
desc.setValue(user, "Alice");
boolean writable = desc.isWritable();

Security | 安全性:

  • Thread-safe: No (not synchronized) - 线程安全: 否(未同步)
  • 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:
  • Constructor Details

    • PropertyDescriptor

      public PropertyDescriptor(String name, Class<?> propertyType, Type genericType, Method readMethod, Method writeMethod, Field field, Class<?> declaringClass)
      Creates a PropertyDescriptor 创建PropertyDescriptor
      Parameters:
      name - the property name | 属性名
      propertyType - the property type | 属性类型
      genericType - the generic type | 泛型类型
      readMethod - the getter method (can be null) | getter方法(可为null)
      writeMethod - the setter method (can be null) | setter方法(可为null)
      field - the field (can be null) | 字段(可为null)
      declaringClass - the declaring class | 声明类
  • Method Details

    • getName

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

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

      public Type getGenericType()
      Gets the generic type 获取泛型类型
      Returns:
      the generic type | 泛型类型
    • getReadMethod

      public Method getReadMethod()
      Gets the read method (getter) 获取读取方法(getter)
      Returns:
      the read method or null | 读取方法或null
    • getWriteMethod

      public Method getWriteMethod()
      Gets the write method (setter) 获取写入方法(setter)
      Returns:
      the write method or null | 写入方法或null
    • getField

      public Field getField()
      Gets the field 获取字段
      Returns:
      the field or null | 字段或null
    • getDeclaringClass

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

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

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

      public Object getValue(Object target)
      Gets the property value 获取属性值
      Parameters:
      target - the target object | 目标对象
      Returns:
      the value | 值
    • setValue

      public void setValue(Object target, Object value)
      Sets the property value 设置属性值
      Parameters:
      target - the target object | 目标对象
      value - the value | 值
    • getAnnotation

      public <A extends Annotation> Optional<A> getAnnotation(Class<A> annotationClass)
      Gets an annotation from this property 从此属性获取注解
      Type Parameters:
      A - the annotation type | 注解类型
      Parameters:
      annotationClass - the annotation class | 注解类
      Returns:
      Optional of annotation | 注解的Optional
    • hasAnnotation

      public boolean hasAnnotation(Class<? extends Annotation> annotationClass)
      Checks if property has annotation 检查属性是否有注解
      Parameters:
      annotationClass - the annotation class | 注解类
      Returns:
      true if has annotation | 如果有注解返回true
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object