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();}}
rc 是被代理的对象,ph是自己创建的对象,然后用 Proxy 创建代理实例再调用方法。
,让所有的愁向后飞去。请不要回头去追你因该向前奔跑,因为快乐在前方!