I need to have the same method but having different argument types :
public interface IKid<T,D,S> {
public T findCookie(D id);
public T findCookie(S id);
}
So that I can do this while implementing this interface :
public class NaughtyKid implements IKid<Foo, Loo, Moo> {
public Foo findCookie(Loo id);
public Foo findCookie(Moo id);
}
But, I get this error in the interface :
Method findCookie(D) has the same erasure findCookie(Object) as another method in type IKid<T,D,S>.
Is there anyway to avoid this problem?
Thank you!
Is there anyway to avoid this problem?
You just need to provide different names for the methods - it's as simple as that.
Aside from anything else, that removes the obvious problem if you implement IKid<Object, String, String>
and want to provide two different implementations for the two different interface methods which would have the same signature after type replacement.
It also makes it much easier to understand any code using the interface, as you'll be able to tell at a glance which method is being called without hunting down type arguments.
See more on this question at Stackoverflow