title: Submitting FutureTasks to an Executor - why does it work?
body: <p>I have the following test code.</p>
  
  <pre><code>import java.util.concurrent.ExecutorService;
  import java.util.concurrent.Executors;
  import java.util.concurrent.FutureTask;
  
  class  MyTask extends FutureTask&lt;String&gt;{
      @Override
      protected void done() {
          System.out.println("Done");
      }
  
      public MyTask(Runnable runnable) {
          super(runnable,null);
      }
  }
  
  public class FutureTaskTest {
  
      public static void main(String[] args)  {
          ExecutorService executor = Executors.newSingleThreadExecutor();
          FutureTask&lt;String&gt; future = new MyTask(new Runnable() {
              public void run() {
                  System.out.println("Running");
              }
          });
  
          executor.submit(future);
  
          try {
              future.get();
          } catch (Exception ex ) {
              ex.printStackTrace();
          }
          executor.shutdownNow();
  
      }
  }
  </code></pre>
  
  <p>This works fine - the overridden 'done' methond in MyTask is called when the task is done.
  But how does the executor know how to call that ?</p>
  
  <p>The executor only have these submit methods:</p>
  
  <pre><code>public &lt;T&gt; Future&lt;T&gt; submit(Callable&lt;T&gt; task);
  public Future&lt;?&gt; submit(Runnable task);
  </code></pre>
  
  <p>Internally it seems 'submit' wraps the callable/runnable in a new FutureTask().
  As far as the executor is concerned I've submitted a Runnable or Callable - from what I gather from these 2 signatures.
  How does it know I submitted a FutureTask and know how to call my overridden done() ?</p>