There is a question which was recently asked to me in an interview.
Problem: There is a class meant to profile the execution time of the code. The class
This can also be done with Lambdas in Java 8. In this case you pass your function to the StopWatch
class and then tell the StopWatch
to execute that code.
Class StopWatch {
long startTime;
long stopTime;
private void start() {// set startTime}
private void stop() { // set stopTime}
void execute(Runnable r){
start();
r.run();
stop();
}
long getTime() {// return difference}
}