Class AbstractInvocationHandler

java.lang.Object
cloud.opencode.base.reflect.proxy.AbstractInvocationHandler
All Implemented Interfaces:
InvocationHandler

public abstract class AbstractInvocationHandler extends Object implements InvocationHandler
Abstract Invocation Handler 抽象调用处理器

Base class for creating custom invocation handlers. Provides default implementations for Object methods.

创建自定义调用处理器的基类。 为Object方法提供默认实现。

Features | 主要功能:

  • Default equals/hashCode/toString handling - 默认equals/hashCode/toString处理
  • Simplified handler implementation - 简化的处理器实现

Usage Examples | 使用示例:

InvocationHandler handler = new AbstractInvocationHandler() {
    protected Object handleInvocation(Object proxy, Method method, Object[] args) {
        return method.invoke(target, args);
    }
};

Security | 安全性:

  • Thread-safe: Depends on subclass implementation - 线程安全: 取决于子类实现
  • Null-safe: No (caller must ensure non-null proxy) - 空值安全: 否(调用方须确保非空代理)
Since:
JDK 25, opencode-base-reflect V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Constructor Details

    • AbstractInvocationHandler

      protected AbstractInvocationHandler()
      Default constructor 默认构造器
  • Method Details

    • invoke

      public final Object invoke(Object proxy, Method method, Object[] args) throws Throwable
      Specified by:
      invoke in interface InvocationHandler
      Throws:
      Throwable
    • handleInvocation

      protected abstract Object handleInvocation(Object proxy, Method method, Object[] args) throws Throwable
      Handles the actual method invocation 处理实际的方法调用
      Parameters:
      proxy - the proxy object | 代理对象
      method - the method | 方法
      args - the arguments | 参数
      Returns:
      the result | 结果
      Throws:
      Throwable - if an error occurs | 如果发生错误
    • handleObjectMethod

      protected Object handleObjectMethod(Object proxy, Method method, Object[] args)
      Handles Object class methods 处理Object类方法
      Parameters:
      proxy - the proxy object | 代理对象
      method - the method | 方法
      args - the arguments | 参数
      Returns:
      the result | 结果
    • handleDefaultMethod

      protected Object handleDefaultMethod(Object proxy, Method method, Object[] args) throws Throwable
      Handles interface default methods 处理接口默认方法
      Parameters:
      proxy - the proxy object | 代理对象
      method - the method | 方法
      args - the arguments | 参数
      Returns:
      the result | 结果
      Throws:
      Throwable - if an error occurs | 如果发生错误
    • proxyEquals

      protected boolean proxyEquals(Object proxy, Object other)
      Determines equality for the proxy 确定代理的相等性
      Parameters:
      proxy - the proxy | 代理
      other - the other object | 另一个对象
      Returns:
      true if equal | 如果相等返回true
    • proxyHashCode

      protected int proxyHashCode(Object proxy)
      Computes hash code for the proxy 计算代理的哈希码
      Parameters:
      proxy - the proxy | 代理
      Returns:
      the hash code | 哈希码
    • proxyToString

      protected String proxyToString(Object proxy)
      Returns string representation for the proxy 返回代理的字符串表示
      Parameters:
      proxy - the proxy | 代理
      Returns:
      the string representation | 字符串表示
    • equals

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

      public int hashCode()
      Overrides:
      hashCode in class Object