Java abstract class with generic lists
<p>I'm trying to define an abstract class that takes in a List of things and does stuff. Something like:</p>

<pre><code>abstract public class AbstractClass {
    private final List&lt;?&gt; list;

    public AbstractClass(List&lt;?&gt; list) {
        this.list = list;
    }

    public List&lt;?&gt; getList() { return list; }
    abstract void addToList(List&lt;?&gt; list);
}

public class Class1 extends AbstractClass {
    public Class1(List&lt;Integer&gt; list) {
        super(list);
    }

    @Override
    void addToList(List&lt;Integer&gt; list) {
        // do stuff
    }
}

public class Class2 extends AbstractClass {
    public Class2(List&lt;String&gt; list) {
        super(list);
    }

    @Override
    void addToList(List&lt;String&gt; list) {
        // do stuff
    }
}


List&lt;Integer&gt; a = new List&lt;Integer&gt;();
Class1 c1 = new Class1(a);
List&lt;Integer&gt; b = c1.getList();
c1.addToList(a);

List&lt;String&gt; c = new List&lt;String&gt;();
Class2 c2 = new Class2(c);
List&lt;Integer&gt; d = c2.getList();
c2.addToList(c);
</code></pre>

<p>Having <code>addToList</code> with specific types in the subclasses is generating errors, but I don't know if that's a matter of syntax (with my poor knowledge of generics) or what I'm trying to do itself (is it possible to overload an abstract method like that)? </p>