JDK的动态实现代码-->Proxy.newProxyInstance()
来源:互联网 发布:mac弹出u盘 编辑:程序博客网 时间:2024/04/30 11:02
interface ProxyInterFace{ public void proxyMethod();}class TargetObject implements ProxyInterFace{ public void proxyMethod() { System.out.println("我被代理了,哈哈!"); }}class ProxyObject implements InvocationHandler{ //代码的对象 public Object targetObject; public void setTargetObject(Object targetObject) { this.targetObject = targetObject; } public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { //调用,传入一个目标对象,和对应的对象参数 return method.invoke(targetObject, args); }}public class ProxyMain{ public static void main(String[] args) { //代理的目标对象 ProxyInterFace proxyInterface = new TargetObject(); //代理器 ProxyObject proxyObject = new ProxyObject(); proxyObject.setTargetObject(proxyInterface); //转换成InvocationHandler InvocationHandler handler = proxyObject; //执行代码任务 Object proxy = Proxy.newProxyInstance(proxyInterface.getClass().getClassLoader(), proxyInterface.getClass().getInterfaces(),handler ); //转换成目标对象,调用目标对象的方法 ((ProxyInterFace)proxy).proxyMethod(); }}
- JDK的动态实现代码-->Proxy.newProxyInstance()
- Proxy.newProxyInstance动态代理[z]
- 动态代理之Proxy.newProxyInstance()
- Proxy.newProxyInstance()
- 解决Proxy.newProxyInstance创建动态代理导致类型转换错误的问题
- Dynamic Proxy(JDK自带的动态代理实现)
- JAVA动态代理之java.lang.reflect.Proxy.newProxyInstance源码
- 从Proxy.newProxyInstance说起
- 代理模式 Proxy.newProxyInstance
- java 代理Proxy.newProxyInstance
- 代理Proxy.newproxyinstance
- 自己实现JDK的Proxy
- 从代理模式再出发!Proxy.newProxyInstance的秘密
- Spring(十)通过动态代理(JDK的Proxy)和cglib实现AOP技术
- 动态代理(3)- newProxyInstance()实现原理
- jdk动态代理实现代码
- 使用JDK中的Proxy技术实现AOP功能[动态代理]
- JDK使用InvocationHandler和Proxy实现动态代理
- 二分多重匹配模板
- Http方法:Get请求与Post请求的区别
- 根据Debug和Release状态的变化来屏蔽日志输出
- OpenGL纹理尺寸限制
- 人生处事的一些经验
- JDK的动态实现代码-->Proxy.newProxyInstance()
- poj2406 kmp 最小重复子串
- CRC校验算法 转
- freemaker笔记
- 通过jquery dialog为什么提交不了form表单 和 $("#Form").ajaxSubmit(options) is not a function 的原因
- linux java 分析工具jstact- java stack
- Android Native Coding in C (OpenGL)
- java常用的连接池02
- 通过人脸判断性别