Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Generic methods doubt

 
Andry Dub
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?

 
Sandip Sarkar
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,

Have a look at the below forum discussion---

web page

i hope it will answer you.

thanks.
 
Nitesh Kant
Bartender
Posts: 1638
IntelliJ IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Kelvin Chenhao Lim
Ranch Hand
Posts: 513
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Andry,

I'm not sure what the issue here is. The code you provided compiles fine.
 
prajal Mehta
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi kevin,

That code is from this site- http://www.javabeat.net/javabeat/scjp5/mocks/Generics-part2-7questions.php
question no. 3

 
prajal Mehta
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am not sure if the answer given is correct.
Please somebody explain the correct answer to me ..
 
Alexsandra Carvalho
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I really dont understand why this does not compile:


//call 2
List<? extends Object> ls2 = new LinkedList<Object>();
addandDisp(ls2,new Object());
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic