title: Java, store method reference for later execution
body: <p>In java 8, I would like to store method reference. </p>
  
  <p>The context is: my program may not be able to execute methods right now but must execute them before it terminates. So my objective is to store these methods in a dedicated class that will execute them before program terminates.</p>
  
  <p>So far, here is what I tried:</p>
  
  <p>I have an interface that matches what the method prototype should be:</p>
  
  <pre><code>public interface IExecutable {
      public void method(String[] args);
  }
  </code></pre>
  
  <p>I have a class that is supposed to store methods and their arguments:</p>
  
  <pre><code>import java.util.HashMap;
  import java.util.Map;
  
  public class LateExecutor {
  
      private Map&lt;String[], IExecutable&gt; tasks = new HashMap&lt;&gt;();
  
      public void execute() {
          tasks.forEach((args, method) -&gt; method(args));
      }
  
      public void storeTask(String[] args, IExecutable method) {
          tasks.put(args, method);
      }
  }
  </code></pre>
  
  <p>With this, I wanted to call <code>storeTask</code> with something like this, from another class:</p>
  
  <pre><code>lateExecutor.storeTask(arrayOfArgs, object::method)
  </code></pre>
  
  <p>But with the current state of the <code>LateExecutor</code> class, I have the following error on <code>-&gt; method(</code>:</p>
  
  <blockquote>
    <p>The method method(String[]) is undefined for the type LateExecutor</p>
  </blockquote>
  
  <p>Which I understand because LateExecutor does not have this method.</p>
  
  <p>However that leaves me with the following problem: <strong>How to store method reference and execute them later</strong> (Any other idea to solve my problem is also welcomed).</p>