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

Generics compilation error

 
Amit K K Amit
Greenhorn
Posts: 8
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4565
8
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Never write code when you are tired. :-)

That was a silly mistake. Thanks Matthew
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic