aspose file tools
The moose likes Java in General and the fly likes Generics problem Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "Generics problem" Watch "Generics problem" New topic
Author

Generics problem

Ronwaldo Cruz
Ranch Hand

Joined: Oct 17, 2006
Posts: 69
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

Joined: Jul 23, 2007
Posts: 203
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.



http://subodh-gupta.blogspot.com
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19216

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:


SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
Ronwaldo Cruz
Ranch Hand

Joined: Oct 17, 2006
Posts: 69
This helped. Thanks
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Generics problem
 
Similar Threads
JPA Composite PK with FK problem
Generics declaration meaning
GWT can't compile SMC generated code
using EL to get at derrived attributes
@ManyToOne & @JoinColumn