Skip to content

Commit 221372c

Browse files
authored
Merge pull request #2698 from juwencheng/patch-1
Update proxy.md
2 parents 1ccf42f + 546f4c0 commit 221372c

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

docs/java/basis/proxy.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -330,10 +330,10 @@ public class DebugMethodInterceptor implements MethodInterceptor {
330330

331331

332332
/**
333-
* @param o 被代理的对象(需要增强的对象
333+
* @param o 代理对象本身(注意不是原始对象,如果使用method.invoke(o, args)会导致循环调用
334334
* @param method 被拦截的方法(需要增强的方法)
335335
* @param args 方法入参
336-
* @param methodProxy 用于调用原始方法
336+
* @param methodProxy 高性能的方法调用机制,避免反射开销
337337
*/
338338
@Override
339339
public Object intercept(Object o, Method method, Object[] args, MethodProxy methodProxy) throws Throwable {
@@ -387,7 +387,7 @@ after method send
387387

388388
### 3.3. JDK 动态代理和 CGLIB 动态代理对比
389389

390-
1. **JDK 动态代理只能代理实现了接口的类或者直接代理接口,而 CGLIB 可以代理未实现任何接口的类。** 另外, CGLIB 动态代理是通过生成一个被代理类的子类来拦截被代理类的方法调用,因此不能代理声明为 final 类型的类和方法。
390+
1. **JDK 动态代理只能代理实现了接口的类或者直接代理接口,而 CGLIB 可以代理未实现任何接口的类。** 另外, CGLIB 动态代理是通过生成一个被代理类的子类来拦截被代理类的方法调用,因此不能代理声明为 final 类型的类和方法,private 方法也无法代理
391391
2. 就二者的效率来说,大部分情况都是 JDK 动态代理更优秀,随着 JDK 版本的升级,这个优势更加明显。
392392

393393
## 4. 静态代理和动态代理的对比

0 commit comments

Comments
 (0)