This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell 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


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: 19697
    
  20

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
How To Ask Questions How To Answer Questions
 
GeeCON Prague 2014
 
subject: Need Explanation for a question in Generics