Which one to use cglib or javaassist

懵懂的女人 提交于 2019-12-10 10:49:08

问题


what is the difference between working of cglib and javaassist

  1. Does cglib creates proxies runtime?
  2. How does javaassist creates proxies?
  3. What is bytecode instrumentation?
  4. How hibernate uses these libraries?

回答1:


The best bytecode manipulation library is ASM (http://asm.ow2.org/). It's really fast and simple to understand.




回答2:


Byte Buddy is a code generation library for creating Java classes during the runtime of a Java application and without the help of a compiler. Other than the code generation utilities, it allows the creation of arbitrary classes and is not limited to implementing interfaces for the creation of runtime proxies.

Byte Buddy is good alternative to both cglib and javaassist. Have a look at Benchmarking various alternatives among Byte Buddy, cglib, javaassist and jdkproxy.

Have a look at SE question regarding the same.

Regarding your queries:

Bytecode instrumentation: ( from cs.helsinki)

Bytecode instrumentation is a process where new function- ality is added to a program by modifying the bytecode of a set of classes before they are loaded by the virtual machine :

Both cglib and javassist were created early and their APIs were built around the language features that Java had to offer back in these days.

Annotation is significant innovations introduced after the inception of these libraries.

Byte Buddy uses annotations and a domain specific language for achieving its ambitions.



来源:https://stackoverflow.com/questions/32451754/which-one-to-use-cglib-or-javaassist

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!