For proof of concept, I want to create a class Exe_Timer with a method timer() such that I can pass any method (for example, add(a,b)) into it, so that I can print the execution time (along with all of the relevant info such as the method name and passed arguments).
Many of the other approaches I've seen would simply take the output of add() and pass it into the other method. But I am only interested in having add() be run BY the other method, so I can make it print the execution time just by calling timer().
For example, I would be able to do this:
public class Main {
public static void main(String[] args) {
Exe_Timer exetimer = new Exe_Timer();
Class2 maths = new Class2;
exetimer.timer(maths.add(a,b)); // passes add(a,b) as a call-able method, not as its output
}
}
But this poses a typing problem as passing add(a,b) would be equivalent to passing the return of the method into timer(). But is there any way to pass the method itself as an argument, and have it be run inside the other method? Thanks