I am attempting to override a method declaration within an interface that extends another interface. Both of these interfaces use generics. According to the Java tutorials, this should be possible, but the example does not use generics. When I try to implement it, the compiler shows the following error (I’ve replaced names because some of the code is not my own.):
myMethod(T) in InterfaceExtended
clashes with myMethod(T) in Interface;
both methods have the same erasure,
but neither overrides the other.
Code looks like this:
public interface Interface<T>
{
public void myMethod(T x);
}
public interface ExtendedInterface<T> extends Interface<T>
{
public void myMethod(T x);
}
If anyone has suggestions as to how to alter this to make it acceptable, or an explanation regarding the reason this is causing a problem, I would very much appreciate it.
Thanks!
badPanda
Do you want an overloaded version of myMethod? Then you should not use T twice, but like this:
Now it is possible to have something like this:
Edit: interestingly enough, this also works (although it is useless):