黑马程序员技术交流社区
标题: 代码问题 [打印本页]
作者: 一诺千金 时间: 2014-3-31 15:18
标题: 代码问题
public class test1 {
public static void main(String[] args){
final ArrayList target = newArrayList();
List proxy =(List)Proxy.newProxyInstance(----------------------这行一直报错什么情况?
List.class.getClassLoader(),
ArrayList.class.getInterfaces(),
new InvocationHandler() {
@Override
public Object invoke(Object proxy,Method method, Object[] args)
throws Throwable {
long beginTime =System.currentTimeMillis(); Thread.sleep(10);
Object reVal = method.invoke(target,args); long endTime = System.currentTimeMillis();
System.out.println(method.getName()+"runing time is "+(endTime-beginTime));
return reVal;
}
});
proxy.add("nihaoa");
proxy.add("nihaoa");
}
} proxy.add("nihaoa");proxy.remove("nihaoa"); System.out.println(proxy.toString());
作者: ノtrack 时间: 2014-3-31 15:19
没学到这里,不过我来顶贴了...
作者: 一年_Hei 时间: 2014-3-31 15:35
你 Thread.sleep(10);没加异常处理,List.class.getClassLoader(),ArrayList.class.getInterfaces(),这两句加包名试试看,建议你用target.getClass().getClassLoader(),target.getClass().getInterfaces(),自己没运行,就是看了下代码,也不知道自己对不对
作者: 枫儿 时间: 2014-4-6 19:47
楼主你好,如果问题已解决,请将帖子改为提问结束,如果没有解决请楼主继续提问,谢谢合作
| 欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) |
黑马程序员IT技术论坛 X3.2 |