您的位置:首页 > 编程语言 > Java开发

java动态代理

2015-07-22 22:59 555 查看
java中的动态代理,我将其粗暴地理解为,将某一对象的某一方交与代理类,代理类在执行此方法的前后可以做一些自定义操作。

在实现动态代理的过程中,会涉及到InvocationHandler接口和Proxy类

其中,InvocationHanlder固名思义,是处理类,一些自定义操作就在此实现。

而Proxy类则是创建动态代理:

@param loader the class loader to define the proxy class

@param interfaces the list of interfaces for the proxy class

to implement

@param h the invocation handler to dispatch method invocations to

@return a proxy instance with the specified invocation handler of a

proxy class that is defined by the specified class loader

and that implements the specified interfaces



Proxy.newProxyInstance(ClassLoader loader,
Class<?>[] interfaces,
InvocationHandler h) throws
IllegalArgumentException



代码实现的例子到处都是,就不贴了。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: