title: Implementing Abstract Generic Method in Java with multiple generics types
body: <p>It is about generics methods in java with two generics types (one for return type and another for a formal parameter) and how to implement it.
  I guess i am missing something in the picture to get it work.</p>
  <p>The matter is this...</p>
  <p>This is <strong>working</strong> :</p>
  <pre><code>public enum Getter
  {
      BillItemsSize {
          @Override
          public Integer get (Object entity) {
              DesiredClass ref = (DesiredClass ) entity; // &quot;Old time&quot; cast
              // do things...
          }
      };
  
      public abstract &lt;T,K&gt; T get (K entity);        
  }
  </code></pre>
  <p>This is <strong>not working</strong> :</p>
  <pre><code>public enum Getter
  {
      BillItemsSize {
          @Override
          public Integer get (DesiredClass entity) { // no cast at all
              // do things
          }
      };
  
      public abstract &lt;T,K&gt; T get (K entity);        
  }
  </code></pre>
  <p>The java compiler yells me this :</p>
  <pre><code>&lt;anonymous datasource.db.Getter$1&gt; is not abstract and does not override abstract method &lt;T,K&gt;get(K) in Getter
  </code></pre>
  <p>Well, that's the situation.
  Thanks in advance to all!.
  Hope it helps others in the future!.</p>
  <p>P.D: It's not a problem of enums types.. it happens across classes hierarchies. So don't bother blaming the enums, i tried this and doesn't work.</p>
  <pre><code>public abstract class SuperClass
  {
      public abstract &lt;T,E&gt; T pepe (E e);
  }
  
  public class SubClass extends SuperClass
  {
  
      @Override
      public Integer pepe(DesiredClass e) // fails... 
      {
          return null;
      }
      
  }
  </code></pre>
  <h2>UPDATED:</h2>
  <p><strong>For Generics parameters</strong></p>
  <p>We can make a general rule statement that for &quot;generics parameter&quot; (those whose types is generic) the type implicitly taken in the method signature is equals to upper limits of that generic, that can be Object, if nothing is specified, or a more specific subclass if upper bounds are used (in example T extends String).</p>
  <p><strong>For Generics returns types</strong></p>
  <p>There is no problem overwriting a generic method with a specific return type, as long the return type is a subtype of the overwritten return type. And what is the return type at first place? Well, it happens to be Object. By default the compiler assumes (in the method signature) the generic type as an Object type.</p>
  <p>So  we have to thing that the trick is to know that any method that have a generic return type are actually having an <strong>Object</strong> return type.
  Then if in any subclasses the method is overwritten and we alter he return type stating that return another type, there will be no problem. Because, besides that method will return an object of another class, that object returned will inevitable be subclass of the Object class and there will be no problem overwrite a method with a different return type that the original as long it be a subtype of the original. The technique called covariant return type allow us to do such thing.</p>
  <pre><code>public abstract class SuperClass
  {
      public abstract &lt;T&gt; T operation ();
  }
  
  
  public class SubClass extends SuperClass
  {
  
      @Override
      public Chair operation()
      {
          //bla bla 
      }
      
  }   
  </code></pre>
  <p>meanwhile in another part of the code...</p>
  <pre><code>void main ()
  {
          SubClass sb = new SubClass();
          Chair chair = sb.operation ();
          // the chair type can be easely replaced by super type (like Object)
          Object object = sb.operation();
  }
  </code></pre>
  <p>Thanks to all the folks who help clear this out!.</p>