Read return value of method using javassist
I want to read the return value of a method and I have to pass it to the code that I insert using the .insertAfter method.
Example:
public String sayHello(){
return "1";
}
I want to add some code, say someClass.someMethod () using javassist.
method.insertAfter("someClass.someMethod(<how to add that value here>);");
Can anyone let me know how to do this?
[Edit] I cannot edit the body of the method because other code may be present. The above method is just an example.
+3
Santosh Tulasiram
source
to share
1 answer
This works for me:
method.insertAfter( "System.err.println( $_ );");
If the method returns void, then $ _ will be null. So, in your case, I think this will work:
method.insertAfter( "someClass.someMethod( $_ );");
where someMethod takes an object.
+2
James
source
to share