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

后端 未结 2 2136
无人共我
无人共我 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:20

    I get the same problem, i solved it this way, may be cannot apply for your test case:

    Make CtClass a private static variable of your Class.

    Create a method that check's if CtClass is already built. If CtClass is not built, call the method that builds it, else, return that CtClass.

    Make that all your test use the new method.

    So, if you have N Test, just the first one will attempt to Built the CtClass, the rest of them will have the static CtClass Variable.

提交回复
热议问题