Difference between CGLIB JDK Dynamic Proxies
生活随笔
收集整理的這篇文章主要介紹了
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)?
轉載于:https://blog.51cto.com/danni505/346896
總結
以上是生活随笔為你收集整理的Difference between CGLIB JDK Dynamic Proxies的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: SVN的恢复历险记
- 下一篇: 第 8 章 配置listener监听器