aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Explain Wildcard Error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Explain Wildcard Error" Watch "Explain Wildcard Error" New topic
Author

Explain Wildcard Error

vishal mishra
Ranch Hand

Joined: Jul 12, 2010
Posts: 103
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

Joined: Dec 05, 2012
Posts: 305

extends means only subtypes will be allowed and super means itself and parent will be allowed.


My one regret in life is that I am not someone else.
- Woody Allen
Himai Minh
Ranch Hand

Joined: Jul 29, 2012
Posts: 812
    
    1




Joe Allen
Ranch Hand

Joined: Nov 14, 2012
Posts: 93
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


"There are no dumb questions" quoted from HFSJ. "To err is human; to forgive is divine"
OCPJP 6, OCEJWCD 6
vishal mishra
Ranch Hand

Joined: Jul 12, 2010
Posts: 103
Thanks all of you for replying and please explain me my next silly question...
Thanks
Himai Minh
Ranch Hand

Joined: Jul 29, 2012
Posts: 812
    
    1
Vishal,
What is your next question?
vishal mishra
Ranch Hand

Joined: Jul 12, 2010
Posts: 103
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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Explain Wildcard Error