title: How to iterate over a wildcard generic?
body: <p>How can I iterate over a wildcard generic? Basically I would like to inline the following method:</p>
  
  <pre><code>private &lt;T extends Fact&gt; void iterateFacts(FactManager&lt;T&gt; factManager) {
      for (T fact : factManager) {
          factManager.doSomething(fact);
      }
  }
  </code></pre>
  
  <p>If this code is in a separate method as shown, it works because the generic method context allows to define a wildcard type (here <code>T</code>) over which one can iterate. If one tries to inline this method, the method context is gone and one cannot iterate over a wildcard type anymore. Even doing this automatically in Eclipse fails with the following (uncompilable) code:</p>
  
  <pre><code>...
  for (FactManager&lt;?&gt; factManager : factManagers) {
      ...
      for ( fact : factManager) {
          factManager.doSomething(fact);
      }
      ...
  }
  ...
  </code></pre>
  
  <p>My question is simply: Is there a way to put some wildcard type one can iterate over, or is this a limitation of generics (meaning it is impossible to do so)?</p>