Class RecordComponent

java.lang.Object
cloud.opencode.base.reflect.record.RecordComponent

public class RecordComponent extends Object
Record Component Wrapper Record组件包装器

Wraps a java.lang.reflect.RecordComponent with additional utilities.

用额外工具包装java.lang.reflect.RecordComponent。

Features | 主要功能:

  • Component type and name access - 组件类型和名称访问
  • Accessor method invocation - 访问器方法调用
  • Annotation access on components - 组件上的注解访问

Usage Examples | 使用示例:

List<RecordComponent> components = OpenRecord.getComponents(User.class);
RecordComponent comp = components.get(0);
String name = comp.getName();
Object value = comp.getValue(userRecord);

Security | 安全性:

  • Thread-safe: Yes (immutable after construction) - 线程安全: 是(构造后不可变)
  • Null-safe: No (component must be non-null) - 空值安全: 否(组件须非空)
Since:
JDK 25, opencode-base-reflect V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Constructor Details

    • RecordComponent

      public RecordComponent(RecordComponent component)
      Creates a RecordComponent wrapper 创建RecordComponent包装器
      Parameters:
      component - the underlying component | 底层组件
  • Method Details

    • getName

      public String getName()
      Gets the component name 获取组件名称
      Returns:
      the name | 名称
    • getType

      public Class<?> getType()
      Gets the component type 获取组件类型
      Returns:
      the type | 类型
    • getGenericType

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

      public Method getAccessor()
      Gets the accessor method 获取访问器方法
      Returns:
      the accessor | 访问器
    • getDeclaringClass

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

      public Object getValue(Object record)
      Gets the value from a record instance 从record实例获取值
      Parameters:
      record - the record instance | record实例
      Returns:
      the value | 值
    • getValue

      public <T> T getValue(Object record, Class<T> type)
      Gets the value with type 获取值(带类型)
      Type Parameters:
      T - the value type | 值类型
      Parameters:
      record - the record instance | record实例
      type - the expected type | 期望类型
      Returns:
      the value | 值
    • getAnnotation

      public <A extends Annotation> A getAnnotation(Class<A> annotationClass)
      Gets an annotation from this component 从此组件获取注解
      Type Parameters:
      A - the annotation type | 注解类型
      Parameters:
      annotationClass - the annotation class | 注解类
      Returns:
      the annotation or null | 注解或null
    • findAnnotation

      public <A extends Annotation> Optional<A> findAnnotation(Class<A> annotationClass)
      Finds an annotation (Optional) 查找注解(Optional)
      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 annotation is present 检查注解是否存在
      Parameters:
      annotationClass - the annotation class | 注解类
      Returns:
      true if present | 如果存在返回true
    • getAnnotations

      public Annotation[] getAnnotations()
      Gets all annotations on this component 获取此组件上的所有注解
      Returns:
      array of annotations | 注解数组
    • unwrap

      public RecordComponent unwrap()
      Gets the underlying RecordComponent 获取底层RecordComponent
      Returns:
      the underlying component | 底层组件
    • getIndex

      public int getIndex()
      Gets the index of this component 获取此组件的索引
      Returns:
      the index | 索引
    • isPrimitive

      public boolean isPrimitive()
      Checks if this component is primitive 检查此组件是否为原始类型
      Returns:
      true if primitive | 如果是原始类型返回true
    • isArray

      public boolean isArray()
      Checks if this component is an array 检查此组件是否为数组
      Returns:
      true if array | 如果是数组返回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