标签:
package com.chapter1.dynamicproxy; import java.lang.reflect.InvocationHandler; import java.lang.reflect.Method; public class ProxyHandler implements InvocationHandler{ private Object proxied; public ProxyHandler(Object proxied){ this.proxied = proxied; } @Override public Object invoke(Object proxy, Method m, Object[] args) throws Throwable { // TODO Auto-generated method stub System.out.println("before"); m.invoke(this.proxied, args); return null; } }
package com.chapter1.dynamicproxy; import java.lang.reflect.Proxy; public class Test { public static void main(String[] args) { RealCoder rc = new RealCoder(); ProxyHandler ph = new ProxyHandler(rc); Coder proxyc = (Coder)Proxy.newProxyInstance(rc.getClass().getClassLoader(),rc.getClass().getInterfaces(), ph); proxyc.coding(); } }
标签:
原文地址:http://blog.csdn.net/cqs_experiment/article/details/45843053