0

The below @Override annotation indicates that I am not overriding the method defined in the interface. How do I use generics with my concrete class so that it overrides the interface method?

public interface AInterface<T extends MyType> {

  void do(T thing)
}

public abstract class BaseMyClass implments AInterface {
  // other stuff
}

// AType extends MyType
public class MyClass extends BaseMyClass <AType> {

  @Overide 
  public void doThing(AType atype) {

  }
}
ab11
  • 19,770
  • 42
  • 120
  • 207
  • Don't use raw types: http://stackoverflow.com/questions/2770321/what-is-a-raw-type-and-why-shouldnt-we-use-it – JB Nizet May 02 '16 at 21:26

1 Answers1

3

BaseMyClass is implementing the rawtype of AInterface, you either need to extend the generic to the abstract class itself or define it:

public abstract class BaseMyClass implments AInterface<AType>
public abstract class BaseMyClass<E extends MyType> implments AInterface<E>

BaseClass<AType> (assuming you meant BaseMyClass) isn't actually giving you a AInterface<AType>

Rogue
  • 11,105
  • 5
  • 45
  • 71