zoukankan      html  css  js  c++  java
  • java动态代理

    @Test
        public void test(){
            
            //new UserImpl();
        /*    ProxyT  proxy=new ProxyT(new UserImpl());
            proxy.add();
            proxy.update();*/
            final User user=new UserImpl();
            User userProxy=(User) Proxy.newProxyInstance(user.getClass().getClassLoader(), new Class[]{User.class}, new InvocationHandler(){
                /**
                 * 参数
                 * ClassLoader loader:被代理的类加载器
                 * Class<?>[] interfaces:被代理类的接口,注意这里的数组一定是接口类,否则出错
                 * InvocationHandler h:将具体调用代理对象时产生的行为
                 */
                @Override
                public Object invoke(Object proxy, Method method, Object[] args)
                        throws Throwable {
                    /**
                     * proxy:
                     * method:代理类正在调用的方法,该处是add
                     * args:add方法所传入的参数
                     */
                    // TODO Auto-generated method stub
                    System.out.println(method);
                    System.out.println("hehehehehhehe");
                    //method.invoke(user, args);
                    return 0;
                }
                
            });
            userProxy.add();
        }

  • 相关阅读:
    delphi 浮点 精度
    delphi 线程 TTask
    IOS 阻止 锁屏
    grideh SelectedRows Bookmark
    TBluetoothLE.OnDisconnectDevice
    TBluetoothLEDevice.UpdateOnReconnect
    判断字符串为空 为null
    delphi IOS 简单类型转换
    setKeepAliveTimeout
    IOS 后台之长时间任务 beginBackgroundTaskWithExpirationHandler 申请后台十分钟 600秒
  • 原文地址:https://www.cnblogs.com/liuquande/p/3804237.html
Copyright © 2011-2022 走看看