Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Need Explanation for a question in Generics  RSS feed

 
thanvi janu
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,



Question:


Answer was: Fails to compile.

can some one explain me the answer.


Thanks a lot,
thanvi
 
Rob Spoor
Sheriff
Posts: 20893
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!