Difference between CGLIB & JDK Dynamic Proxies

As we know, create proxy in runtime, we can use two different techniques, CGLIB or JDK dynamic proxies, what's different between them? when should we use CGLIB? and when should we use JDK proxies? here we have short view about it.
 
JDK dynamic proxise
If the target class implements one or more interfaces, we should create a JDK dynamic proxy that implements every interface.
 
(Tip:The source code case can see the article:http://danni505.blog.51cto.com/15547/217359)
 
CGLIB Proxy
If the target class implements no interfaces, one class itself, in this case, the JDK proxy may be not can used, we should better use CGLIB to create a new class on the fly that is a subclass ("extends") the target class.
(Tip:The source code case can see the article:《How does proxy do in CGLIB?》)
 
Compare
Compare above two articles we can find this conclusion:
JDK dynamic proxy cannot be casted to the original target class because it's simply a dynamic proxy that happens to implement the same interface(s) as the target. This has the effect of "nudging" you to program to interfaces if they're being used in your application's model, since proxies will usually be invoked through those interfaces.
 
On the other hand, if interfaces are completely absent from your model, create CGLIB proxies that can be treated more-or-less just like the target class itself.
 
(Tip: Welcome any discussion with people thinking this things, msn me by danni-505@hotmail.com)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值