How to properly override an abstract method with generics in the signature
generics, inheritance, java
Solution
You should do
public class Derived<T> extends Base<T>
You need to specify `<T>` for `Base` otherwise you will have to override method by simply declaring `List` i.e.without generics
Problem
I thought I understood how to do this but I'm getting some unexpected behavior so apparently I'm missing something. Here's the problem boiled down. Base Class: ``` public abstract class Base<T> { abstract public void foo(List<? extends T> l); } ``` Derived Class: ``` public class Derived<T> extends Base { @Override public void foo(List<? extends T> l) { return; } } ``` The Base class complies fine, but when I compile the Derived class I get: Derived.java:3: Derived is not abstract and does not override abstract method foo(java.util.List) in Base public class Derived extends Base ^ Derived.java:5: method does not override or implement a method from a supertype ``` @Override ^ ``` 2 errors The generics of the parameter `List<? extends T>` appears to be the cause of the problem. If I replace that part in both signatures with the basic type `int` it comples fine. Can anybody tell me what's going on here?