Why does the following
public class ListBox {
private Random random = new Random();
private List extends Collection
You've declared box
to be a List
of something that extends Collection
of Object
. But according to the Java compiler, it could be anything that extends Collection
, i.e. List<Vector<Object>>
. So it must disallow add
operations that take the generic type parameter for this reason. It can't let you add an ArrayList<Object>
to a List
that could be List<Vector<Object>>
.
Try removing the wildcard:
private List<Collection<Object>> box;
This should work because you can certainly add an ArrayList<Object>
to a List
of Collection<Object>
.