The class library byte code Javassist

Javassist advantage

- less than the cost of reflection, high performance.
-Javassist performance than reflective, less than ASM
bytecode manipulation allows us to achieve the following functions Runtime:
- dynamically generate a new class
- a class to dynamically change the configuration (add / delete / modify the new property / method)
Javassist API outermost layer and reflection JAVA API package is quite similar.
It mainly consists of CtClass, CtMethod,, and CtField several classes. For the java.lang.Class, java.lang.reflect.Method, perform the same operation and JDK java.lang.reflect.Method .Field reflection API.
The method of operation
- The method of modifying existing method body (body inserting code into existing methods)
- Method new method deletes


Limitations of javassist
JDK5.0 does not support the new syntax (including generics, enumerations), it does not support annotations modification, but can be addressed by the underlying javassist class, specific reference: javassist.bytecode.annotation
not initialize an array of support, such as String [] { "1", "2"}, unless there is only a capacity of the array is
not supported by internal and anonymous classes
do not support the break and continue expressions.
For inheritance, and some do not. E.g.
class A {}  
class B {A} the extends 
class B {C} the extends 

 

Guess you like

Origin www.cnblogs.com/pickKnow/p/11128864.html