title: How to surround a callback invocation with another piece of code in a best way?
body: <p>I have a simple, functional interface:</p>
  
  <pre><code>public interface Callback&lt;T&gt; {
      void invoke(T param);
  }
  </code></pre>
  
  <p>I make many asynchronous operations like:</p>
  
  <pre><code>public void getSubfolders(Folder folder, Callback&lt;FolderList&gt; result){
      asyncExecutor.submit(() -&gt; {
          FolderList list = folder.get_SubFolders();
          result.invoke(list);
      });
  }
  </code></pre>
  
  <p>The results must be processed on a <code>main thread</code>. For that, I have a <code>JavaFX</code> method:</p>
  
  <p><code>Platform.runLater(Runnable task);</code></p>
  
  <p>Which makes my code a mess like this one (and this pattern is repeated in 50 other methods):</p>
  
  <pre><code>public void getSubfolders(Folder folder, Callback&lt;FolderList&gt; result){
       asyncExecutor.submit(() -&gt; {
           FolderList list = folder.get_SubFolders();
           Platform.runLater(() -&gt; result.invoke(list));
       });
  }
  </code></pre>
  
  <p>I'd like to wrap each callback invocation with <code>Platform.runLater(...)</code>.
  The only thing I came up with is a <code>default method</code>:</p>
  
  <pre><code>public interface Callback&lt;T&gt; {
      void invoke(T param);
  
      default void invokeOnMain(T param){
          Platform.runLater(() -&gt; invoke(param));
      }
  }
  </code></pre>
  
  <p>And then, I just call <code>result.invokeOnMain(list)</code>.</p>
  
  <p>Is there a better approach for patterns like this one?</p>