|
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());
|