This week's book giveaway is in the OCAJP 8 forum.
We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line!
See this thread for details.
The moose likes Java in General and the fly likes Need Explanation for a question in Generics Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Need Explanation for a question in Generics" Watch "Need Explanation for a question in Generics" New topic
Author

Need Explanation for a question in Generics

thanvi janu
Greenhorn

Joined: Nov 16, 2009
Posts: 29
Hi All,



Question:


Answer was: Fails to compile.

can some one explain me the answer.


Thanks a lot,
thanvi
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 20136
    
  30

Because you use a wildcard in the declaration of house, the compiler no longer knows it is a AnimalHouse<Cat>. For all it knows it could be an AnimalHouse<Dog>, AnimalHouse<Bird> or even AnimalHouse<String>*. You need to replace the "?" with either "Cat" or "? super Cat".


* Change the declaration of AnimalHouse to this:
This way the generic type is bound to be Animal or any subtype.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Need Explanation for a question in Generics
 
It's not a secret anymore!