• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Explain Wildcard Error

 
vishal mishra
Ranch Hand
Posts: 103
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Namaste Friends !!
I am too weak in Generics and still trying to clear my concept...

Following question is giving Wildcard Error-: "no suitable method is found for add(A)"

Please explain why obj A can not be added to the ArrayList<A>, as it will accept only object of type class A ?
And after doing certain modifications this code compiles without error...

Modified Program-:


Modifications-: "extends" replace with "super" and "B" is changed with "A"

Again when i tried to compile program given below , same error occurred...


Please explain why obj A can not be added ??
Thanks
 
meeta gaur
Ranch Hand
Posts: 305
Notepad Tomcat Server Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
extends means only subtypes will be allowed and super means itself and parent will be allowed.
 
Himai Minh
Ranch Hand
Posts: 1226
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator




 
Joe Allen
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I had the same problem like yours. You can see this link
http://www.coderanch.com/t/607980/java-programmer-SCJP/certification/generic-type-instantiation
 
vishal mishra
Ranch Hand
Posts: 103
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks all of you for replying and please explain me my next silly question...
Thanks
 
Himai Minh
Ranch Hand
Posts: 1226
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Vishal,
What is your next question?
 
vishal mishra
Ranch Hand
Posts: 103
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Himai Minh wrote:Vishal,
What is your next question?

My next question is here http://www.coderanch.com/t/608217/java-programmer-SCJP/certification/Reference-variable-calls-method-instance


Thank for your reply..

Although I have clicked on resolved button but for any further explanation I will be really Thankful to You

I have read your previous explanations and those are really good one..
Thank You
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic