P
petek1976
Can anyone tell me why this code will not compile? I'm only including
the relevant portions of the code. I don't understand the error from
the compiler:
public class Msg
{
}
public interface MsgListener<T>
{
public void Process(T msg);
}
import java.util.*;
public class MsgRegistration
{
private HashMap<String,MsgListener<? extends Msg>> mcMap = new
HashMap<String,MsgListener<? extends Msg>>();
public <X extends Msg> void doit(String acName, X acMsg)
{
MsgListener<? extends Msg> lcListener= mcMap.get(acName);
lcListener.Process(acMsg);
}
}
MsgRegistration.java:10: Process(capture of ? extends Msg) in
MsgListener<capture of ? extends Msg> cannot be applied to (X)
lcListener.Process(acMsg);
Why can't it be applied to X since X extends Msg?
the relevant portions of the code. I don't understand the error from
the compiler:
public class Msg
{
}
public interface MsgListener<T>
{
public void Process(T msg);
}
import java.util.*;
public class MsgRegistration
{
private HashMap<String,MsgListener<? extends Msg>> mcMap = new
HashMap<String,MsgListener<? extends Msg>>();
public <X extends Msg> void doit(String acName, X acMsg)
{
MsgListener<? extends Msg> lcListener= mcMap.get(acName);
lcListener.Process(acMsg);
}
}
MsgRegistration.java:10: Process(capture of ? extends Msg) in
MsgListener<capture of ? extends Msg> cannot be applied to (X)
lcListener.Process(acMsg);
Why can't it be applied to X since X extends Msg?