I have created a list like below.
ArrayList<? extends Object> arr = new ArrayList<Object>();
what i understand by above line this is an upper bounding any element which is subclass of object can be added to the list. Now I am trying like this:
String str = new String("str");
Integer i = new Integer(4);
Object obj = new Object();
arr.add(obj);
arr.add(str);
arr.add(i);
They all are giving error.What is the problem here? But when I change it to
ArrayList<? super Object> arr = new ArrayList<Object>();
All works.It is lower bounding. Can anyone explain it to me.