This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Generics compilation error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Generics compilation error" Watch "Generics compilation error" New topic
Author

Generics compilation error

Amit K K Amit
Greenhorn

Joined: Oct 10, 2011
Posts: 8

Hi Guys,
I am trying to compile the follwing code, can anyone tell me what is the issue in the code?



Compilation Error Message :-
=====================

dotestgenericswithpoly(java.util.List<? extends Animal>) in TestGenerics cannot
be applied to (Cat)
dotestgenericswithpoly(new Cat());

[Edit - added code tags - see UseCodeTags]
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4344
    
    8

It's not the generics that are the problem - that wouldn't work in a non-generic version. The problem is that you're passing a Cat to a method that's expecting a List.
Amit K K Amit
Greenhorn

Joined: Oct 10, 2011
Posts: 8

Never write code when you are tired. :-)

That was a silly mistake. Thanks Matthew
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Generics compilation error
 
Similar Threads
invalid cast exception
Why can't we assign parent class object to child class reference?
Type of the Generic List
polymorphism doubt
Inheritance, overriding methods