problem casting to an interface
Hi,
The "IDInterface anId=((MsgInterface)anMsg).getMsgId();" line in the following code gets me with:
.../SwarmSystem/src/swarm/sys/mail/Mailbox.java:85: cannot find symbol
symbol : method getMsgId()
location: class java.lang.Object
IDInterface anId=((MsgInterface)anMsg).getMsgId();
That is i cast to an interface -although there should be really no need to, since i use generics- and then call the "getMsgId" method. The cast, however, doesn't work and the method seems to be called on an java.lang.Object object.
publicclass Mailbox<MsgInterface>
{
privateboolean empty=true;
privateint size=0;
private Collection<MsgInterface> msgBox=new HashSet<MsgInterface>();
private ID id;
private String label="";
private Level logLevel;
public Mailbox(ID id, String label,Level logLevel)
{
this.id=id;
this.label=label;
this.logLevel=logLevel;
initLogger(logLevel);
}//Mailbox
...
publicsynchronized Collection<MsgInterface> removeAndGetMessages()
{
while (empty)
{
try
{
wait();
}
catch(InterruptedException e)
{
}
}
Collection<MsgInterface> msgBoxCopy=new HashSet<MsgInterface>();
msgBoxCopy.addAll(msgBox);
//logging
String nsMsgId="";
if (!(logLevel==Level.OFF))
{
Iterator<MsgInterface> iMsgBox=msgBox.iterator();
while (iMsgBox.hasNext())
{
MsgInterface anMsg=iMsgBox.next();
IDInterface anId=((MsgInterface)anMsg).getMsgId();
nsMsgId=nsMsgId+ anId.toString()+" ";
}
}
cat.info("removing all messages from mailbox "+id.toString()+": "+nsMsgId);
//logging
msgBox.clear();
empty=true;
notifyAll();
return msgBoxCopy;
}//removeAndGetMessages
...
}
publicinterface MsgInterface
{
public IDInterface getMsgId();
public IDInterface getSender();
public IDInterface getReceiver();
public Object getLoad();
publicvoid setLoad(Object data);
}
publicinterface IDInterface
{
public String getType();
public String getBody();
publicint getIntBody();
}

