Javassist: re-creating a class - delete first, or defrost() and modify?

后端 未结 2 2142
无人共我
无人共我 2021-02-10 03:28

I use Javassist to create a class. And in a test suite, when a second test tries to create the same class, it fails at pool.makeClass( ... ) because the class is fr

2条回答
  •  暗喜
    暗喜 (楼主)
    2021-02-10 04:17

    You cannot unload a single class from a ClassLoader. A class may be unloaded if it and its ClassLoader became unreachable but since every class refers to its loader that implies that all classes loaded by this loader must have become unreachable too.

    But you can (re-)create the class using a different ClassLoader. Well, formally it is a different class with the same name (and maybe the same byte code) then. If the code executed within the test case leaves no references in the heap, the ClassLoader and its classes might be collected after the test.

提交回复
热议问题