I have few classes A, B, C and D where B extends A, C extends A and D extends A
I then have the following ArrayLists with few elements in them
ArrayList<B> b;
ArrayList<? extends A> mix = b;
I created this ArrayList mix in order to contain elements of B, C or D. I then try to add an element of type C into the mix ArrayList
mix.add(anElementOfTypeC);
The IDE doesn't allow me to do so and it says anElementOfTypeC cannot be converted to CAP#1 by method of invocation conversion where CAP#1 is a fresh type-variable: CAP#1 extends A from capture of ? extends A
Did I use the <? extends A>
correctly and how to resolve this?
Thanks in advance.
mix
is actually anArrayList<B>
here... – fge Jan 13 at 17:32