Adding an annotation to a runtime generated method/class using Javassist

前端 未结 1 1683
挽巷
挽巷 2020-12-15 05:02

I\'m using Javassist to generate a class foo, with method bar, but I can\'t seem to find a way to add an annotation (the annotation itself isn\'t r

相关标签:
1条回答
  • 2020-12-15 05:44

    Solved it eventually, I was adding the annotation to the wrong place. I wanted to add it to the method, but I was adding it to the class.

    This is how the fixed code looks like:

    // wrong
    ccFile.addAttribute(attr);
    
    // right
    mthd.getMethodInfo().addAttribute(attr);
    
    0 讨论(0)
提交回复
热议问题