java-自带proxy

此版本为jdk 提供的类proxy里面的方法实现的。。


下一部将献上纯人工编写的 aop 实例代码。 敬请期待


Collection coll1 =(Collection)Proxy.newProxyInstance(Collection.class.getClassLoader(),
new Class[]{Collection.class},
new InvocationHandler() {
  ArrayList target = new ArrayList();
@Override
public Object invoke(Object proxy, Method method, Object[] args)
throws Throwable {

Object returnVal = method.invoke(target, args);
return returnVal;
}
});
  coll1.add("wjj1");
  coll1.add("wjj2");
  System.out.println(coll1.size());
}

你可能感兴趣的:(java,AOP,jdk)