• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Generics in Interfaces

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You wouldn't if your implementing class would also use the wildcard:
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic