How to change method behaviour through reflection?

后端 未结 2 1813
一整个雨季
一整个雨季 2020-12-01 15:52

I have a a static method in some legacy code, which is called by multiple clients. I obviously have no options to override it, or change behaviour through dependency injecti

2条回答
  •  忘掉有多难
    2020-12-01 16:31

    I guess you could have a look at Instrumentation class which have a method redefineClasses(ClassDefintion classDefinition).

    The redefinition may change method bodies, the constant pool and attributes. The redefinition must not add, remove or rename fields or methods, change the signatures of methods, or change inheritance.

    Hope this helps.

    References: Javadoc

提交回复
热议问题