R
rossum
Is there a way to deal with interfaces which have clashing method
definitions?
I am trying to write my own queue, based on a Hashtable:
public class HashQueue<E>
extends Hashtable<Integer, E>
implements Queue<E> { ... }
This combination beings in interfaces Collection, Map, Dictionary and
Queue. I am having problems with the method remove(). There are
different versions with different return values in the various
interfaces:
Queue has: E remove()
Collection has: boolean remove(Object o)
Dictionary has: E remove(E elem)
The Queue version has a different signature to the other two so that
is not a problem. My problem is that the compiler is telling me that
the Dictionary remove does not match the Collection remove return
value and vice versa. It seems that the compiler is treating Object
and E as the same. How can I tell the compiler which of my
implementations of remove belongs to Collection and which to
Dictionary? I have tried Collection.remove and (Collection)remove but
neither work.
A short example:
interface FileStuff {
String read();
}
interface ConsoleStuff {
int read();
}
class Stuff implements FileStuff, ConsoleStuff {
public String read() { return "Hello World!"; }
// public String FileStuff.read() { return "Hello World!"; }
// public String (FileStuff)read() { return "Hello World!"; }
public int read() { return 42; }
}
Is there a way round this problem?
Thanks in advance.
rossum
definitions?
I am trying to write my own queue, based on a Hashtable:
public class HashQueue<E>
extends Hashtable<Integer, E>
implements Queue<E> { ... }
This combination beings in interfaces Collection, Map, Dictionary and
Queue. I am having problems with the method remove(). There are
different versions with different return values in the various
interfaces:
Queue has: E remove()
Collection has: boolean remove(Object o)
Dictionary has: E remove(E elem)
The Queue version has a different signature to the other two so that
is not a problem. My problem is that the compiler is telling me that
the Dictionary remove does not match the Collection remove return
value and vice versa. It seems that the compiler is treating Object
and E as the same. How can I tell the compiler which of my
implementations of remove belongs to Collection and which to
Dictionary? I have tried Collection.remove and (Collection)remove but
neither work.
A short example:
interface FileStuff {
String read();
}
interface ConsoleStuff {
int read();
}
class Stuff implements FileStuff, ConsoleStuff {
public String read() { return "Hello World!"; }
// public String FileStuff.read() { return "Hello World!"; }
// public String (FileStuff)read() { return "Hello World!"; }
public int read() { return 42; }
}
Is there a way round this problem?
Thanks in advance.
rossum