title: Can I pass a Method as parameter of another method in java?
body: <p>I am trying to measure the execution time for several methods. so I was thinking to make a method instead of duplicate same code many times.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>private void MeasureExecutionTime(Method m)
  {
      startTime = System.nanoTime();
      try
      {
          m();
      }
      finally
      {
          endTime = System.nanoTime();
      }
      elapsedTime = endTime - startTime;
      System.out.println("This takes " + elapsedTime + " ns.");
  }
  </code></pre>
  
  <p>Suppose I have <code>myMethod()</code>, how can I use <code>MeasureExecutionTime()</code> to measure <code>myMethod</code>'s execution time?</p>