• Post Reply Bookmark Topic Watch Topic
  • New Topic

Generics problem  RSS feed

 
Ronwaldo Cruz
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I have written a piece of code show below:



The problem is that the interface method Dog.getOwner seems to have been successfully "implemented" by ConcreteDog.getHunter. However, Dog.setOwner doesn't seem to recognize ConcreteDog.setHunter as a suitable implementation. The 2 looks the same to me. Can somebody please help?

 
subodh gupta
Ranch Hand
Posts: 203
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

You cannot use extends in both the get and put logic you should use extends for getting and super for putting a variable of a type.

 
Rob Spoor
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It seems to me that you want to connect the Person type in both getOwner and setOwner. Changing the T to a class generic type could solve this:
 
Ronwaldo Cruz
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This helped. Thanks
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!