File tree Expand file tree Collapse file tree 1 file changed +10
-0
lines changed
src/com/blankj/custom/desingn_pattern/proxys/dynamicProxy Expand file tree Collapse file tree 1 file changed +10
-0
lines changed Original file line number Diff line number Diff line change 4
4
5
5
public class Client {
6
6
public static void main (String [] args ) {
7
+
8
+ // 一个典型的动态代理创建对象过程可分为以下四个步骤:
9
+ // 1、通过实现InvocationHandler接口创建自己的调用处理器 IvocationHandler handler = new InvocationHandlerImpl(...);
10
+ // 2、通过为Proxy类指定ClassLoader对象和一组interface创建动态代理类
11
+ // Class clazz = Proxy.getProxyClass(classLoader,new Class[]{...});
12
+ // 3、通过反射机制获取动态代理类的构造函数,其参数类型是调用处理器接口类型
13
+ // Constructor constructor = clazz.getConstructor(new Class[]{InvocationHandler.class});
14
+ // 4、通过构造函数创建代理类实例,此时需将调用处理器对象作为参数被传入
15
+ // Interface Proxy = (Interface)constructor.newInstance(new Object[] (handler));
16
+
7
17
ISubject subject = new RealSubject ();
8
18
9
19
InvocationHandler handler = new MyInvocationHandler (subject );
You can’t perform that action at this time.
0 commit comments