How to use super Use javassist to insert code after XXX ()

class A extends B{
class A extends B{
public void a(){
    super.a();
    System.out.println("hello");
}
}

I want to use javassist in super Insert some code after XXX, for example:

class A extends B{
public void a(){
    super.a();
    System.out.println("inject"); // javassist 
    System.out.println("hello");
}
}

If the original code does not contain super XXX, then just inject code and use method insertBefore.

My question is how to identify whether the method contains "super. XXX" and how to insert code as described above

Solution

Depending on your code, it looks like the end of the method you want to insert code, so you can use the classpool insertafter () method to add a line at the end of a specific method

You can also use the insertat () method, but it is always inserted before the specified line number

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>