日期:2014-05-20 浏览次数:20668 次
package util; import java.lang.reflect.InvocationHandler; import java.lang.reflect.Method; import java.lang.reflect.Proxy; import java.util.ArrayList; import java.util.List; public class ArrayListProxy implements InvocationHandler { List list = null; public ArrayListProxy(){ this.list = new ArrayList(); } public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { long starttime = System.currentTimeMillis(); Object o = method.invoke(list, args); System.out.println(method.getName()+"() 执行了"+(System.currentTimeMillis()-starttime)); return o; } public static List getArrayList(){ return (List)Proxy.newProxyInstance(ArrayList.class.getClassLoader(), new Class[]{List.class}, new ArrayListProxy()); } public static void main(String[] args) { List list = getArrayList(); for(int i = 10000; i < 20005; i ++){ list.add(i); } list.size(); List list2 = getArrayList(); for(int i = 10006; i < 40021; i ++){ list2.add(i); } list.contains(list); } }