The whole idea of Generics is type-safety and preventing casts.
When i add() to a list that is <? super A>
, the only way it lets me compile the get is to declare the variable type as Object.
ArrayList<? super A> list = new ArrayList<A>();
Object obj = list.get(0);
The fact is that I can only add A and A's sub-classes to this list.
So one, why doesnt it let me declare obj as type A?
A obj = list.get(0);
And two, the fact that type is now Object
, it seems to loosen up the whole Generics idea - i am containing it in a umbrella type, and i need to cast the .get()