• Post Reply Bookmark Topic Watch Topic
  • New Topic

Generics in Interfaces  RSS feed

 
R. Heydenreich
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I have tho following Interface:


This Interface is implemented by the following class:


Now the compiler complaints about "Name clash: The method handleResult(List<MyDomainObject> ) of type MyObjects has the same erasure as handleResult(List<? extends AbstractDomainObject> ) of type MyHandler but does not override it".

MyDomainObject extends AbstractDomainObject, therefore I thought it's a correct use of generics. If I omit the generic in the implementing class the compiler only warns "References to generic type List<E> should be parameterized". What's the problem???

TIA,
Ralf.
[ December 04, 2008: Message edited by: R. Heydenreich ]
 
Chandra Bhatt
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,

I think you have some other method named handleResult(...) in MyHandler or Job
interface where the type erasure of this method signature comes same instead
of overriding the method.
 
Chandra Bhatt
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does MyObjects class overrides handleResult(...) method? I see gotcha there.
Is that?
 
R. Heydenreich
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you have some other method named handleResult(...) in MyHandler or Job
interface where the type erasure of this method signature comes same instead
of overriding the method.

No, this is the only one method I have in this interface.

Does MyObjects class overrides handleResult(...) method? I see gotcha there.
Is that?

Yes, it overrides the method.
 
Rob Spoor
Sheriff
Posts: 21131
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No it doesn't. public <T> void handleResult(List<? extends AbstractDomainObject> result) and public void handleResult(List<MyDomainObject> mylist) do not have the same signature; if class X directly extends AbstractDomainObject then one can accept List<X> but the other can't.

You may want to use generics on the entire interface:
 
R. Heydenreich
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah, thanks, it helps! I thought that I don't need to use the generic in the interface declaration.
 
Rob Spoor
Sheriff
Posts: 21131
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You wouldn't if your implementing class would also use the wildcard:
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!