Basically I need to have an abstract class, that contains a field of a list that details it can hold subclasses of a certain class, and then create a concrete class that stores a specific subclass of that certain class.
Better explained in code I am sure:
public class A {
}
public class B extends A {
}
public abstract class AbsClass {
protected List<? extends A> list;
}
public class ConClass extends AbsClass {
list = new ArrayList<B>();
}
With the above code i get the compiler error
The method add(capture#3-of ? extends A) in the type List < capture#3-of ? extends A> is not applicable for the arguments (B)
the line where the list is instantiated.
How can I get this to work?
list.add, not with your assignment. Your code won't compile for other reasons; namely the assignment occurs outside of a constructor or initializer block.Ais a class, not a type parameter. A bit misleading since it's one character but it's a common fake class name, and it's included in the question.