title: Variable callables with different return types
body: <p>The problem I have in hand is that I methods <code>one(), two(), three(), four()</code> that have a different return types say, <code>A, B, C, D</code> and I need to spawn variable numbers of threads (one for each method depending on the use case. This means I would want to call a subset of methods at a time.) Now, am using the <code>cachedThreadPool</code> to submit these callables. Some code below:</p>
  
  <pre><code>public class Dispatcher {
  
    public void dispatch(List&lt;MethodNames&gt; methodNames) {
      //Now I am going to iterate through the list of methodNames
      //And submit each method to the `ExecutorService`
      for(MethodNames m : methodNames) {
        switch(m) {
          case ONE: //submit one()
                    //wait and get the future
                    Future&lt;A&gt; future = cachePool.submit(new Callable&lt;A&gt;() {
                      @Override
                      public A call() {
                        return one();
                      });
                    A response = future.get(); 
               break;
          ....
        }
      }
    }
  }
  
  public enum MethodNames {
    ONE, TWO, THREE, FOUR
  }
  
  //Example methods:
  public A one() {
  }
  
  public B two() {
  }
  </code></pre>
  
  <p>My question is how do the above such that all the method calls are made without having to wait for one to finish. Also, how do I gather all the <code>futures</code> and wait for them to finish cause all the futures have a different generic type <code>Future&lt;A&gt;, Future&lt;B&gt;</code> etc. I make the call to <code>submit()</code> inside the case statement so I don't have the access to the returned <code>Future&lt;T&gt;</code> outside the case. Now I could do an <code>if, else</code> instead of the <code>for</code> loop but I am trying to figure out if there is a better way to achieve this.</p>