- public static void main(String[] args) {
- List list = (List) Proxy.newProxyInstance(List.class.getClassLoader(),
- List.class.getInterfaces(),
- new InvocationHandler() {
- List arrayList = new ArrayList();
- public Object invoke(Object proxy, Method method,
- Object[] args) throws Throwable {
- long startTime = System.currentTimeMillis();
- Object retVal = method.invoke(arrayList, args);
- long endTime = System.currentTimeMillis();
- System.out.println(endTime - startTime);
- return retVal;
- }
- });
- list.add("kd");
- list.remove(0);
复制代码
代码总是报类型转换异常,我自我感觉没错误,请大神帮忙 |
|