I have a class, controlBase
, that is inherited by other child classes. How can I make a list of any of these child classes?
I have tried:
private ArrayList<? extends controlBase> controllers = new ArrayList();
However, this doesn't allow any classes to be added to it. With the above example, this throws an error:
public <T extends controlBase> void registerController(Class<T> c) {
controllers.add(c);
}
An error is also thrown when I execute:
controllers.add(new controlBase());
or
controllers.add(new joystick()); // Joystick is a child-class of controlBase
This does not allow any classes to be added, even in the first example where it explicitly states that the class extends controlBase
.
How can I make this arrayList be only of objects that extend the controlBase
class?