What is the difference between JDK dynamic proxy and CGLib?
问题 In case of the Proxy Design Pattern, What is the difference between JDK\'s Dynamic Proxy and third party dynamic code generation API s such as CGLib? What is the difference between using both the approaches and when should one prefer one over another? 回答1: JDK Dynamic proxy can only proxy by interface (so your target class needs to implement an interface, which is then also implemented by the proxy class). CGLIB (and javassist) can create a proxy by subclassing. In this scenario the proxy