62,620
社区成员
发帖
与我相关
我的任务
分享
public class Test {
public static void main(String[] args) {
// 被代理的对象
Father f= new Father ();
/**
* 通过InvocationHandlerImpl的构造器生成一个InvocationHandler对象,
* 需要传入被代理对象作为参数
*/
InvocationHandler handler = new InvocationHandlerImpl(realSubject);
ClassLoader loader = f.getClass().getClassLoader();
// 需要指定类装载器、一组接口及调用处理器生成动态代理类实例
Subject subject = (Subject) Proxy.newProxyInstance(loader,new Class[]{Father.class}, handler);
}
}