I have a class with a generic T. Then I create an ArrayList with a generic that holds T or any of its subobjects. I assign it to an ArrayList with generic T. Why can I not add to it. Here is the code snippet:
ArrayList<? extends T> list = new ArrayList<T>();
T t; //yes I know it is null currently, but this is the idea
list.add(t); //will not compile
I know it will throw a NullPointer, but that's not the issue. Why won't it let me add a T object to an ArrayList declared that it can be instantiated with an ArrayList of type T and thus instantiated with type T.
-Thanks
P.S. I did not put the code in the snippet but it is in a class with generic T defined.