Create class with javassist and make it available

后端 未结 2 596
逝去的感伤
逝去的感伤 2021-01-15 21:03

I want to do the following:

try {
    Class.forName(\"MyClass\");
} catch(ClassNotFoundException e) {
    ClassPool pool = ClassPool.getDefault();
    CtClas         


        
2条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-15 21:57

    `try {
        Class.forName("MyClass");
    } catch(ClassNotFoundException e) {
    try {
        ClassPool pool = ClassPool.getDefault();
        CtClass cc = pool.makeClass("MyClass");
        Class.forName("MyClass");
    catch(Exception e) {
    }
    }`
    

    Check with this code, sometime jvm optimize the code and shuffle the statements , except in try block.

提交回复
热议问题