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 Generic methods doubt 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 "Generic methods doubt" Watch "Generic methods doubt" New topic

Generic methods doubt

Andry Dub
Ranch Hand

Joined: Nov 06, 2007
Posts: 43
Hi! Please explain me why I can't invoke addandDisp with parameters ls1 and object of type Object? What second parameter is allowed with first parameter will be ls1?

Java is my love
Sandip Sarkar
Ranch Hand

Joined: Nov 25, 2007
Posts: 55

Have a look at the below forum discussion---

web page

i hope it will answer you.

Nitesh Kant

Joined: Feb 25, 2007
Posts: 1638

mmm, i am not sure what you wish to intend by List<? super Object>
This means either a superclass of Object(No class qualifies this rule) or the Object itself.
Since, there is no superclass of Object, its as good as saying List<Object>
If you do the above, everything should work fine.

apigee, a better way to API!
Kelvin Chenhao Lim
Ranch Hand

Joined: Oct 20, 2007
Posts: 513
Hi Andry,

I'm not sure what the issue here is. The code you provided compiles fine.

SCJP 5.0
prajal Mehta
Ranch Hand

Joined: Dec 03, 2007
Posts: 66
Hi kevin,

That code is from this site-
question no. 3

prajal Mehta
Ranch Hand

Joined: Dec 03, 2007
Posts: 66
I am not sure if the answer given is correct.
Please somebody explain the correct answer to me ..
Alexsandra Carvalho
Ranch Hand

Joined: Jul 13, 2007
Posts: 75
I really dont understand why this does not compile:

//call 2
List<? extends Object> ls2 = new LinkedList<Object>();
addandDisp(ls2,new Object());
I agree. Here's the link:
subject: Generic methods doubt
It's not a secret anymore!