javassist frozen classes

阅读 47

2022-02-18


Frozen classes

If a ​​CtClass​​​ object is converted into a class file by ​​writeFile()​​​, ​​toClass()​​​, or ​​toBytecode()​​​, Javassist freezes that ​​CtClass​​​ object. Further modifications of that ​​CtClass​​ object are not permitted. This is for warning the developers when they attempt to modify a class file that has been already loaded since the JVM does not allow reloading a class.

A frozen ​​CtClass​​ can be defrost so that modifications of the class definition will be permitted. For example,

CtClasss cc = ...;
:
cc.writeFile();
cc.defrost();
cc.setSuperclass(...); // OK since the class is not frozen.

After ​​defrost()​​​ is called, the ​​CtClass​​ object can be modified again.


精彩评论(0)

0 0 举报