Class MethodInvokable<T>

java.lang.Object
cloud.opencode.base.reflect.invokable.Invokable<T,Object>
cloud.opencode.base.reflect.invokable.MethodInvokable<T>
Type Parameters:
T - the declaring class type | 声明类类型
All Implemented Interfaces:
AnnotatedElement

public final class MethodInvokable<T> extends Invokable<T,Object>
Method Invokable Implementation 方法Invokable实现

Implementation of Invokable for Method objects.

Method对象的Invokable实现。

Features | 主要功能:

  • Method wrapping as Invokable - 将方法包装为Invokable
  • Type-safe method invocation - 类型安全的方法调用
  • Parameter and annotation access - 参数和注解访问

Usage Examples | 使用示例:

Invokable<Service, Object> invokable = Invokable.from(method);
Object result = invokable.invoke(service, args);

Security | 安全性:

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

    • getMethod

      public Method getMethod()
      Gets the underlying Method 获取底层Method
      Returns:
      the Method | 方法
    • getAccessibleObject

      protected AccessibleObject getAccessibleObject()
      Description copied from class: Invokable
      Gets the underlying accessible object 获取底层可访问对象
      Specified by:
      getAccessibleObject in class Invokable<T,Object>
      Returns:
      the accessible object | 可访问对象
    • getDeclaringClass

      public TypeToken<T> getDeclaringClass()
      Description copied from class: Invokable
      Gets the declaring class as TypeToken 获取声明类的TypeToken
      Specified by:
      getDeclaringClass in class Invokable<T,Object>
      Returns:
      TypeToken of declaring class | 声明类的TypeToken
    • getDeclaringClassRaw

      public Class<?> getDeclaringClassRaw()
      Description copied from class: Invokable
      Gets the declaring class as raw Class 获取声明类的原始Class
      Specified by:
      getDeclaringClassRaw in class Invokable<T,Object>
      Returns:
      the declaring class | 声明类
    • getReturnType

      public TypeToken<Object> getReturnType()
      Description copied from class: Invokable
      Gets the return type as TypeToken 获取返回类型的TypeToken
      Specified by:
      getReturnType in class Invokable<T,Object>
      Returns:
      TypeToken of return type | 返回类型的TypeToken
    • getParameters

      public List<Parameter> getParameters()
      Description copied from class: Invokable
      Gets the parameter list 获取参数列表
      Specified by:
      getParameters in class Invokable<T,Object>
      Returns:
      list of Parameters | 参数列表
    • getParameterTypes

      public List<TypeToken<?>> getParameterTypes()
      Description copied from class: Invokable
      Gets the parameter types 获取参数类型
      Specified by:
      getParameterTypes in class Invokable<T,Object>
      Returns:
      list of parameter TypeTokens | 参数TypeToken列表
    • getExceptionTypes

      public List<TypeToken<? extends Throwable>> getExceptionTypes()
      Description copied from class: Invokable
      Gets the exception types 获取异常类型
      Specified by:
      getExceptionTypes in class Invokable<T,Object>
      Returns:
      list of exception TypeTokens | 异常TypeToken列表
    • getTypeParameters

      public TypeVariable<?>[] getTypeParameters()
      Description copied from class: Invokable
      Gets the type parameters 获取类型参数
      Specified by:
      getTypeParameters in class Invokable<T,Object>
      Returns:
      array of type variables | 类型变量数组
    • invoke

      public Object invoke(T receiver, Object... args) throws InvocationTargetException, IllegalAccessException
      Description copied from class: Invokable
      Invokes the method/constructor 调用方法/构造器
      Specified by:
      invoke in class Invokable<T,Object>
      Parameters:
      receiver - the receiver object | 接收对象
      args - the arguments | 参数
      Returns:
      the result | 结果
      Throws:
      InvocationTargetException - if invocation fails | 如果调用失败
      IllegalAccessException - if access denied | 如果访问被拒绝
    • isVarArgs

      public boolean isVarArgs()
      Description copied from class: Invokable
      Checks if varargs 检查是否为可变参数
      Specified by:
      isVarArgs in class Invokable<T,Object>
      Returns:
      true if varargs | 如果是可变参数返回true
    • isSynthetic

      public boolean isSynthetic()
      Description copied from class: Invokable
      Checks if synthetic 检查是否为合成
      Specified by:
      isSynthetic in class Invokable<T,Object>
      Returns:
      true if synthetic | 如果是合成返回true
    • isBridge

      public boolean isBridge()
      Checks if this is a bridge method 检查是否为桥接方法
      Returns:
      true if bridge | 如果是桥接方法返回true
    • isDefault

      public boolean isDefault()
      Checks if this is a default method 检查是否为默认方法
      Returns:
      true if default | 如果是默认方法返回true
    • getName

      public String getName()
      Description copied from class: Invokable
      Gets the name 获取名称
      Specified by:
      getName in class Invokable<T,Object>
      Returns:
      the name | 名称
    • getModifiers

      public int getModifiers()
      Description copied from class: Invokable
      Gets the modifiers 获取修饰符
      Specified by:
      getModifiers in class Invokable<T,Object>
      Returns:
      the modifiers | 修饰符
    • equals

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

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

      public String toString()
      Overrides:
      toString in class Object