父类:
public class Action
{
private String eventId;
private List<ActionArgument> arguments;
//action to perform when this action is done
private List<? extends Action> onCompleteActions;
public Action(){}
public Action(String eventId, List<ActionArgument> arguments, List<? extends Action> onCompleteActions)
{
this.eventId = eventId;
this.arguments = arguments;
this.onCompleteActions = onCompleteActions;
}
public String getEventId()
{
return eventId;
}
public void setEventId(String eventId)
{
this.eventId = eventId;
}
public List<ActionArgument> getArguments()
{
return arguments;
}
public void setArguments(List<ActionArgument> arguments)
{
this.arguments = arguments;
}
public List<? extends Action> getOnCompleteActions()
{
return onCompleteActions;
}
public void setOnCompleteActions(List<? extends Action> onCompleteActions)
{
this.onCompleteActions = onCompleteActions;
}
}
扩展类:
public class UserDefinedAction extends Action
{
// body not important
}
一些服务:
private boolean arrangeBefore(List<? extends Action> defaultActions, UserDefinedAction action)
{
String actionToFind = action.getDoBefore();
boolean actionFound = false;
for(int i = 0; i < defaultActions.size(); i++)
{
if(defaultActions.get(i).getEventId().toUpperCase().equals(actionToFind.toUpperCase()))
{
defaultActions.add(i, action);
return true;
}
...
所以我在这里有一个错误:defaultActions.add(i, action);
上面写着“
add
(int,
capture<? extends com.myPackage.Action>)
in List cannot be applied
to
(int,
com.myPackage.UserDefinedAction)
"
有人可以向我解释为什么这不起作用吗?