File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Generics Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Generics" Watch "Generics" New topic


anita dhar
Ranch Hand

Joined: Jul 14, 2007
Posts: 69
Anyone expalin this code . This is from generics from K & B book
public static <T> void addandDisp(Collection<T> cs, T t)
for (T o : cs)
for (T o : cs)

//call 1
List<? super Object> ls1 = new LinkedList<Object>();
addandDisp(ls1,new String());

//call 2
List<? extends Object> ls2 = new LinkedList<Object>();
addandDisp(ls2,new Object());

//call 3
List<Object> ls3 = new LinkedList<Object>();
addandDisp(ls3,new String());

//call 4
List<? super Object> ls4 = new LinkedList<Object>();
addandDisp(ls4,new Object());

Which call(s) to above method(addandDisp) are error free?

a)only 3

b)only 1 and 3

c)only 1 and 4

d)only 1,2 and 3

e)only 1,3 and 4

Thanks in advance
I agree. Here's the link:
subject: Generics
It's not a secret anymore!