Java代理,转型异常,怎么解决 ? jdk动态代理只能代理有接口的类, 代理接口方法 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 import java.lang.reflect.InvocationHandler;import java.lang.reflect.Method;import java.lang.reflect.Proxy;public class Test implements InvocationHandler { private Test_1 target; public Object bind(Test_1 target) { this.target = target; return Proxy.newProxyInstance(target.getClass().getClassLoader(), target.getClass().getInterfaces(), this); } public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { Object obj = null; System.out.println(method.getName()); try { obj = method.invoke(target, args); } catch (NullPointerException nullErr) { System.out.println("ok"); return null; } return obj; } public static void main(String[] args) { Interface_Test a = (Interface_Test) new Test().bind(new Test_1()); a.test(); }}interface Interface_Test { public void test();}class Test_1 implements Interface_Test { int i = 9; int j = 9; public void test() { System.out.println("执行Test"); }}给你改了一下。 swing 如何实现如下的状态栏效果? 怎么在表格中添加复选框 用java程序下载文件,如何做,请高手提示一下 我是菜鸟,想参加编程培训,不知是否有效果?请各位给点意见! 菜鸟劳驾大虾一举手之功--经典的数三退一问题源程 设计一程序!! String对象作为参数传递给函数的问题 Map和Set的区别 我想问一下classpath到底怎么设置 哪儿有SCJP的培训教程下载,急! jackson的ObjectMapper是否线程安全 bootstrap modal
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;public class Test implements InvocationHandler {
private Test_1 target; public Object bind(Test_1 target) {
this.target = target;
return Proxy.newProxyInstance(target.getClass().getClassLoader(),
target.getClass().getInterfaces(), this);
} public Object invoke(Object proxy, Method method, Object[] args)
throws Throwable {
Object obj = null;
System.out.println(method.getName());
try {
obj = method.invoke(target, args);
} catch (NullPointerException nullErr) {
System.out.println("ok");
return null;
}
return obj;
} public static void main(String[] args) {
Interface_Test a = (Interface_Test) new Test().bind(new Test_1());
a.test();
}
}interface Interface_Test {
public void test();
}class Test_1 implements Interface_Test {
int i = 9;
int j = 9; public void test() {
System.out.println("执行Test");
}}给你改了一下。