Difference between CGLIB & JDK Dynamic Proxies
2010-07-09 14:50
197 查看
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)
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)
相关文章推荐
- The difference between Proxy and CGLIB
- The difference between static_cast and dynamic_cast
- The difference between Proxy and CGLIB
- Differences between Greedy algorithms && Dynamic Programming
- The difference between static_cast and dynamic_cast
- What is the difference between JRE,JVM and JDK?
- BigDecimal(-)Difference of BigDecimal toString() method between JDK1.4 and above version
- One of the difference between JDK1.6.0 and JDK1.7.0
- JDK Dynamic Proxy and cglib
- Dynamic Proxy of JDK and Cglib
- Difference between Web.Config and Machine.Config File
- Have You Ever Wondered About the Difference Between NOT NULL and DEFAULT?
- Java动态代理机制详解(JDK 和CGLIB,Javassist,ASM) (清晰,浅显)
- What is the difference between --save and --save-dev?
- java动态代理(JDK和cglib)
- What is the difference between concurrency, parallelism and asynchronous methods?
- Java JDK动态代理和cglib动态代理
- Difference between WCF and Web API and WCF REST and Web Service[转]
- 深入探索spring技术内幕(六): JDK动态代理和cglib生成代理
- Difference between menu item types; Display, Output and Action in Dynamics Ax