posted 16 years ago
line 2 and line 3 are wrong because '?' cannot be used with new.
line 1 is wrong because it says::
List<? super Parent> alList = new ArrayList<Child>();
i.e any thing which is a super class of Parent including Parent..
since Child class is a sub-class hence line 1 is wrong..
List<? extends Child> alList = new ArrayList<Parent>();//line 4
this is wrong because it says "anything which is a sub-class of Child(including Child)..and since Parent is a Super Class hence it is also wrong..
line 5 is correct
List<?> alList = new ArrayList<Parent>();
because it says "List<?>" which means anything...it can be a Child or Parent or Integer or Object or Cat or Dog !!
"History would be kind to me, for I intend to write it."