title: Why can't javac infer generic type arguments for functions used as arguments?
body: <p>In the following sample, why is the compiler able to infer the generic arguments for the first call to <code>Foo.create()</code> in <code>Foo.test()</code>, but not able to do so in the second? I'm using Java 6.</p>
  
  <pre><code>public class Nonsense {
      public static class Bar {
          private static void func(Foo&lt;String&gt; arg) { }
      }
  
      public static class Foo&lt;T&gt; {
  
          public static &lt;T&gt; Foo&lt;T&gt; create() {
              return new Foo&lt;T&gt;();
          }
  
          private static void test() {
              Foo&lt;String&gt; foo2 = Foo.create(); // compiles
              Bar.func(Foo.create());          // won't compile
              Bar.func(Foo.&lt;String&gt;create());  // fixes the prev line
          }
      }
  }
  </code></pre>
  
  <p>(The compile error is <em>The method func(Nonsense.Foo) in the type Nonsense.Bar is not applicable for the arguments (Nonsense.Foo)</em>).</p>
  
  <p>Note: I understand the compiler error can be fixed by the third line in test() - I'm curious as to whether there is a specific limitation that prevents the compiler from being able to infer the type. It <em>appears</em> to me that there is enough context for it here.</p>