List the names of methods being invoked
java, reflection
Solution
I would use aspectj to define an aspect which writes log messages for every method call. You can find an example here: Tracing Java Method Execution with AspectJ. or here: Logging with AspectJ
The advantage of this solution is that you don't have to make any changes on your code. You will need some time to get into aspectj, but it meets your requirement very well.
Problem
I'd like to have a reflection-like solution for displaying the methods which are called. Example: ``` public class Foo { public void bar() { new Y().x(); } } public class Y { public void x() { } } public class Main { public static void main(String[] args) { // SETTING UP THE MAGIC new Foo().bar(); new Y().x(); } } ``` The output should be: ``` 1. Foo.bar 1.2 Y.x 2. Y.x ``` Optimally there could be an event handler which would be fired every time a method is called(and some info could be passed as a parameter). PS: I don't want to use this in a production environment, I only need this for displaying output in a skeleton app without dummy copy-paste.