java 代理Proxy.newProxyInstance
来源:互联网 发布:女生low知乎 编辑:程序博客网 时间:2024/04/25 10:24
package proxy;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import javax.swing.plaf.basic.BasicComboPopup.InvocationKeyHandler;
public class Test {
public static void main(String[] args) {
ShowMethod showMethod =new TestValue();
// showMethod.getnae();
InvocationHandler interfacess=new TestPro(showMethod);
ShowMethod showMethod2=(ShowMethod) Proxy.newProxyInstance(showMethod.getClass().getClassLoader(),
showMethod.getClass().getInterfaces(), interfacess);
showMethod2.getnae();
System.out.println(showMethod2.getClass().getName());
System.out.println(showMethod.getClass().getName());
}
static class TestPro implements InvocationHandler{
Object objects;
public TestPro( Object objects) {
this.objects=objects;
// TODO Auto-generated constructor stub
}
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
System.out.println("开始执行");
// TODO Auto-generated method stub
method.invoke(objects, args);
System.out.println("结束执行");
return null;
}
}
interface ShowMethod {
void getnae();
}
static class TestValue implements ShowMethod{
@Override
public void getnae() {
// TODO Auto-generated method stub
System.out.println("执行");
}
}
}
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import javax.swing.plaf.basic.BasicComboPopup.InvocationKeyHandler;
public class Test {
public static void main(String[] args) {
ShowMethod showMethod =new TestValue();
// showMethod.getnae();
InvocationHandler interfacess=new TestPro(showMethod);
ShowMethod showMethod2=(ShowMethod) Proxy.newProxyInstance(showMethod.getClass().getClassLoader(),
showMethod.getClass().getInterfaces(), interfacess);
showMethod2.getnae();
System.out.println(showMethod2.getClass().getName());
System.out.println(showMethod.getClass().getName());
}
static class TestPro implements InvocationHandler{
Object objects;
public TestPro( Object objects) {
this.objects=objects;
// TODO Auto-generated constructor stub
}
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
System.out.println("开始执行");
// TODO Auto-generated method stub
method.invoke(objects, args);
System.out.println("结束执行");
return null;
}
}
interface ShowMethod {
void getnae();
}
static class TestValue implements ShowMethod{
@Override
public void getnae() {
// TODO Auto-generated method stub
System.out.println("执行");
}
}
}
0 0
- java 代理Proxy.newProxyInstance
- 代理模式 Proxy.newProxyInstance
- 代理Proxy.newproxyinstance
- JAVA动态代理之java.lang.reflect.Proxy.newProxyInstance源码
- Proxy.newProxyInstance动态代理[z]
- 动态代理之Proxy.newProxyInstance()
- 使用Proxy.newProxyInstance()代理时,报错java.lang.ClassCastException: com.sun.proxy.$Proxy61
- Proxy.newProxyInstance()
- 从代理模式再出发!Proxy.newProxyInstance的秘密
- 从Proxy.newProxyInstance说起
- 解决Proxy.newProxyInstance创建动态代理导致类型转换错误的问题
- java Proxy代理&cglib代理
- java 代理(proxy)模式
- Java Proxy动态代理
- java Proxy 代理模式
- JAVA实现代理proxy
- Java 动态代理 Proxy
- java代理Proxy
- C#创建access数据库文件,创建表
- 按键精灵实现交易开拓者33个品种回测时间和交易费用的设置
- mysql双master+keepalived实现高可用
- 【mysql】mycat目录结构以及主要配置文件解读
- 保存文件到本地and加载本地文件
- java 代理Proxy.newProxyInstance
- PyNGL和PyNIO教程翻译
- 从输入 URL 到页面展示,到底发生了什么
- Java中堆、栈和堆栈区别
- 系统编程三
- 纯JS实现图片验证码功能并兼容IE6-8
- 自己实现strcpy
- cdh版本hive源码编译打包
- 510上机作业题目(多重派生)