本帖最后由 王金科 于 2012-9-14 01:00 编辑
- public class ProxyDemo {
- public static void main(String[] args) throws Exception{
- final ArrayList target = new ArrayList<>();
- Collection proxy4 = (Collection)getProxy(target,new MyAdvice());
- proxy4.add("asd");//这句话的具体流程是怎么样子的?
- proxy4.clear();
- System.out.println(String.class.getInterfaces());
- }
- private static Object getProxy(final Object target,final Advice advice) {
- Object proxy4 = Proxy.newProxyInstance(
- target.getClass().getClassLoader(),
- target.getClass().getInterfaces(),
- new InvocationHandler(){
- @Override
- public Object invoke(Object proxy, Method method, Object[] args)
- throws Throwable {
- advice.beforeMethod(method);
- Object retVal = method.invoke(target, args);
- advice.afterMethod(method);
- return retVal;
- }
- });
- return proxy4;
- }
- }
复制代码 后面加注释的那句话,具体流程是怎么样子的?谁能给我详细说说? |