Java Design Issue: Enforce method call sequence

后端 未结 12 843
青春惊慌失措
青春惊慌失措 2021-02-02 05:27

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

12条回答
  •  没有蜡笔的小新
    2021-02-02 06:06

    Maybe he expected this 'reconfiguration' and question was not about method sequence at all:

    class StopWatch {
    
       public static long runWithProfiling(Runnable action) {
          startTime = now;
          action.run();
          return now - startTime;
       }
    }
    

提交回复
热议问题