Interface MethodInvoker

Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@FunctionalInterface public interface MethodInvoker
Method Invoker Interface 方法调用器接口

Provides a way to invoke the original method from an interceptor.

提供从拦截器调用原始方法的方式。

Features | 主要功能:

  • Original method invocation from interceptor - 从拦截器调用原始方法
  • No-op and constant factory methods - 空操作和常量工厂方法

Usage Examples | 使用示例:

// Used inside MethodInterceptor
MethodInterceptor interceptor = (proxy, method, args, invoker) -> {
    // invoke the original method
    return invoker.invoke(args);
};

Security | 安全性:

  • Thread-safe: Depends on implementation - 线程安全: 取决于实现
  • Null-safe: No (args may be null for no-arg methods) - 空值安全: 否(无参方法的args可能为null)
Since:
JDK 25, opencode-base-reflect V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    Creates an invoker that always returns a constant 创建一个总是返回常量的调用器
    invoke(Object[] args)
    Invokes the original method 调用原始方法
    Creates a no-op invoker that returns null 创建一个返回null的空操作调用器
  • Method Details

    • invoke

      Object invoke(Object[] args) throws Throwable
      Invokes the original method 调用原始方法
      Parameters:
      args - the arguments | 参数
      Returns:
      the result | 结果
      Throws:
      Throwable - if an error occurs | 如果发生错误
    • noOp

      static MethodInvoker noOp()
      Creates a no-op invoker that returns null 创建一个返回null的空操作调用器
      Returns:
      the no-op invoker | 空操作调用器
    • constant

      static MethodInvoker constant(Object value)
      Creates an invoker that always returns a constant 创建一个总是返回常量的调用器
      Parameters:
      value - the value to return | 要返回的值
      Returns:
      the constant invoker | 常量调用器