Re: Clashing Interface methods



On Sun, 26 Aug 2007 19:46:25 +0100, rossum <rossum48@xxxxxxxxxxxx>
wrote:

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
There obviously being no direct way to solve the problem I ended up
using AbstractQueue with an internal HashMap:

public class HashQueue<E>
extends AbstractQueue<E> {

private m_Data HashMap<Integer, E>;

}

Thanks to everyone for your help.

rossum

.



Relevant Pages

  • Re: Clashing Interface methods
    ... I am trying to write my own queue, ... public class HashQueue ... extends Hashtable ... In the unlikely event that your callers really do need to access the ...
    (comp.lang.java.programmer)
  • Clashing Interface methods
    ... Is there a way to deal with interfaces which have clashing method ... I am trying to write my own queue, ... public class HashQueue ...
    (comp.lang.java.programmer)
  • program challenge
    ... public void setName{ ... the salaried class that extends Employee ... public class Salaried extends Employee ... // Programmer.java: the programmer class that extends from Hourly ...
    (comp.lang.java.help)
  • Re: dynamic tool tip text
    ... public class CustomTextField extends JTextField { ... public String getToolTipText{ ... public void mouseEntered{ ...
    (comp.lang.java.programmer)
  • RE: Design help.
    ... The better design approach is to declare your interfaces first. ... Implemtent the webservices classes from the same interface ... public class OrderService: WebService, IOrder ...
    (microsoft.public.dotnet.framework.webservices)