title: java generic type inference based on generic argument
body: <p>what I'm trying to do is send a generic method(filter) inside generic object(ItemDelegate) to another generic method(getItem). The problem is that the second method(getItem) can not infer the correct type.</p>
  
  <pre><code>// Generic object
  public class ItemDelegate&lt;T&gt; {
      public &lt;T&gt; T filter() {
          return null;
      }
  }
  
  // Generic method (receiver):
  public static &lt;T&gt; T getItem(ItemDelegate&lt;T&gt; delegate) {
      T item = delegate.filter();
      //... do something
      return item;
  }
  
  // Usage in code:
  getItem(new ItemDelegate&lt;String&gt;() {
      public String filter() {
          return "Hi!";
      }
  }
  </code></pre>
  
  <p>this code generates a compile error in getItem:</p>
  
  <p>type parameters of T cannot be determined; no unique maximal instance exists for type variable T with upper bounds T,java.lang.Object</p>
  
  <p>Can this even be done in java or is there a better way.</p>
  
  <p>Thanks.</p>