Get callers method (java.lang.reflect.Method)

Viewed 12687

I would like to get the calling method java.lang.reflect.Method. NOT the name of the method.

Here is an example how to get the callers Class.

// find the callers class
Thread t = Thread.getCurrentThread();
Class<?> klass = Class.forName(t.getStackTrace()[2].getClassName());
// do something with the class (like processing its annotations)
... 

It's for testing purpose only!

4 Answers
Related