0

As far as i know classes generated by cglib are final. why? it doesn't seem to be some fundamental limitation of jvm. is it just an arbitrary decision of cglib creators? is it the case also with jdk and javassist proxies?

piotrek
  • 13,982
  • 13
  • 79
  • 165
  • 1
    I worked with all of those library quite a lot and I would argue that it is arbitrary. One reason for this decision might be that the generated classes include quite some noise (accessor methods etc.) what would make their subclass use rather difficult. – Rafael Winterhalter Mar 20 '14 at 09:03
  • 1
    Proxies are usually designed for *delegation* rather than inheritance so it makes sense to declare them `final` especially for generated proxies which are not available to static code. In the past declaring classes `final` where feasible was considered a potential performance improvement but with modern JVMs that usually doesn’t matter. – Holger Apr 29 '14 at 09:12
  • JDK proxies (java.lang.reflect.Proxy) are also final. Besides Holger's comment, in this case not needing to support subclasses gives the JVM more freedom to implement proxies with "magic". – Jeffrey Bosboom Jul 04 '14 at 16:51

0 Answers0