Module bus.core

Class FieldInvoker

java.lang.Object
org.miaixz.bus.core.lang.reflect.field.FieldInvoker
All Implemented Interfaces:
Invoker

public class FieldInvoker extends Object implements Invoker
字段调用器 通过反射读取或赋值字段 读取字段值:

 FieldInvoker.of(Field).invoke(object);
 

赋值字段值:


 FieldInvoker.of(Field).invoke(object, value);
 
Since:
Java 17+
Author:
Kimi Liu
  • Constructor Details

    • FieldInvoker

      public FieldInvoker(Field field)
      构造
      Parameters:
      field - 字段
  • Method Details

    • of

      public static FieldInvoker of(Field field)
      创建字段调用器
      Parameters:
      field - 字段
      Returns:
      FieldInvoker
    • getField

      public Field getField()
      获取字段
      Returns:
      字段
    • getName

      public String getName()
      Description copied from interface: Invoker
      获取调用方法的名称。
      Specified by:
      getName in interface Invoker
      Returns:
      调用方法的名称,作为字符串返回。
    • getType

      public Type getType()
      Description copied from interface: Invoker
      获取调用方法的返回类型或参数类型或字段类型。
      Specified by:
      getType in interface Invoker
      Returns:
      调用方法的返回类型,作为Class对象返回。
    • getTypeClass

      public Class<?> getTypeClass()
      Description copied from interface: Invoker
      获取调用方法的返回类型或参数类型或字段类型。
      Specified by:
      getTypeClass in interface Invoker
      Returns:
      调用方法的返回类型,作为Class对象返回。
    • setConverter

      public FieldInvoker setConverter(Converter converter)
      设置字段值转换器
      Parameters:
      converter - 转换器,null表示不转换
      Returns:
      this
    • invoke

      public <T> T invoke(Object target, Object... args)
      Description copied from interface: Invoker
      调用指定目标对象的方法。
      Specified by:
      invoke in interface Invoker
      Type Parameters:
      T - 返回类型
      Parameters:
      target - 目标对象,调用的方法属于该对象。
      args - 方法调用的参数数组。
      Returns:
      方法的返回值,方法的返回类型可以是任意类型。
    • invokeGet

      public Object invokeGet(Object object) throws InternalException
      获取字段值
      Parameters:
      object - 对象,static字段则此字段为null
      Returns:
      字段值
      Throws:
      InternalException - 包装IllegalAccessException异常
    • invokeSet

      public void invokeSet(Object object, Object value) throws InternalException
      设置字段值,传入的字段值必须和字段类型一致,否则抛出异常
      Parameters:
      object - 对象,如果是static字段,此参数为null
      value - 值,值类型必须与字段类型匹配
      Throws:
      InternalException - 包装IllegalAccessException异常