I am working on a program where I need to be able to check when certain methods are run on a particular object. I know that's probably a bit unclear, so here's an example.
Let's say that this is the class I am trying to access:
public class Clazz {
public void exampleMethod(ExampleParam param) {
//Unknown code
}
}
- The Clazz object is not created by any of my code. I have no control over its creation.
- The methods of Clazz (in this example, just
exampleMethod(ExampleParam param)
) are not called by any of my code.
What I need to do is have a way to determine when exampleMethod(ExampleParam param)
is called by code that I do not have access to.
The code that is run inside the method is irrelevant to me. All I need to know is:
- Every time the method is called.
- If possible, the parameters that were passed into the method.
- If on the off chance that the above is possible, it would also be useful to know the class that originally called the method.
In other words, is it possible to create a "method called" listener?