• jdk 1.8 InvocationHandler 中文注释


    JDK动态代理实现了接口InvocationHandler重写了invoke类
    动态代理的底层是通过反射技术来实现

    先翻译这一点,知道这是干啥的了。下面的解释以后有机会再翻译

    /*
     * Copyright (c) 1999, 2006, Oracle and/or its affiliates. All rights reserved.
     * ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
     */
    package java.lang.reflect;
    /**
     * {@code InvocationHandler} 由代理实例 invocation handler 实现的接口.
     * invocation handler:调用处理程序
     *
     * <p>每个代理实例都有一个关联的 invocation handler.
     * 当一个方法被一个代理实例调用时, 将对该方法调用进行编码,
     * 并将其调度到invocation handler的 {@code invoke}方法.
     * 
     * @author      Peter Jones
     * @translator  oc
     * @see         Proxy
     * @since       1.3
     */
    public interface InvocationHandler {
        /**
         * 处理代理实例上的方法调用并返回结果。
         * 在与之关联的代理实例上调用方法时,将在调用处理程序上调用该方法。
         *
         * @param   proxy 被调用方法上的代理实例
         *
         * @param   method the {@code Method} instance corresponding to
         * the interface method invoked on the proxy instance.  The declaring
         * class of the {@code Method} object will be the interface that
         * the method was declared in, which may be a superinterface of the
         * proxy interface that the proxy class inherits the method through.
         *
         * @param   args an array of objects containing the values of the
         * arguments passed in the method invocation on the proxy instance,
         * or {@code null} if interface method takes no arguments.
         * Arguments of primitive types are wrapped in instances of the
         * appropriate primitive wrapper class, such as
         * {@code java.lang.Integer} or {@code java.lang.Boolean}.
         *
         * @return  the value to return from the method invocation on the
         * proxy instance.  If the declared return type of the interface
         * method is a primitive type, then the value returned by
         * this method must be an instance of the corresponding primitive
         * wrapper class; otherwise, it must be a type assignable to the
         * declared return type.  If the value returned by this method is
         * {@code null} and the interface method's return type is
         * primitive, then a {@code NullPointerException} will be
         * thrown by the method invocation on the proxy instance.  If the
         * value returned by this method is otherwise not compatible with
         * the interface method's declared return type as described above,
         * a {@code ClassCastException} will be thrown by the method
         * invocation on the proxy instance.
         *
         * @throws  Throwable the exception to throw from the method
         * invocation on the proxy instance.  The exception's type must be
         * assignable either to any of the exception types declared in the
         * {@code throws} clause of the interface method or to the
         * unchecked exception types {@code java.lang.RuntimeException}
         * or {@code java.lang.Error}.  If a checked exception is
         * thrown by this method that is not assignable to any of the
         * exception types declared in the {@code throws} clause of
         * the interface method, then an
         * {@link UndeclaredThrowableException} containing the
         * exception that was thrown by this method will be thrown by the
         * method invocation on the proxy instance.
         *
         * @see     UndeclaredThrowableException
         */
        public Object invoke(Object proxy, Method method, Object[] args)
            throws Throwable;
    }
    
  • 相关阅读:
    Linux 下 Lua 与 LuaSQL 模块安装
    js学习笔记27----键盘事件
    js学习笔记26----事件冒泡,事件捕获
    js学习笔记25----Event对象
    js学习笔记24----焦点事件
    js学习笔记23----窗口尺寸及窗口事件
    js学习笔记22----BOM属性和方法
    VS Code 常用快捷键
    你不知道的JavaScript学习笔记1——作用域
    三种CSS方法实现loadingh点点点的效果
  • 原文地址:https://www.cnblogs.com/ZCWang/p/12766146.html
Copyright © 2020-2023  润新知