의 컬렉션으로 서브 클래스의 컬렉션을 전달 나는 더 많거나 적은 같은 보이는 POJO 있습니다슈퍼 클래스
public class Action {
private String eventId;
private List<ActionArgument> arguments;
//action to perform when this action is done
private List<Action> onCompleteActions;
public Action() {
}
public Action(String eventId, List<ActionArgument> arguments, List<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<Action> getOnCompleteActions() {
return onCompleteActions;
}
public void setOnCompleteAction(List<Action> onCompleteActions) {
this.onCompleteActions = onCompleteActions;
}
}
및 I는 다음과 같이 연장 클래스를 보이는 것을 :
public class UserDefinedAction extends Action {
//for reordering actions with the default actions
private String doBefore;
private String doAfter;
private String doAfterComplete;
public String getDoBefore() {
return doBefore;
}
public void setDoBefore(String doBefore) {
this.doBefore = doBefore;
}
public String getDoAfter() {
return doAfter;
}
public void setDoAfter(String doAfter) {
this.doAfter = doAfter;
}
public String getDoAfterComplete() {
return doAfterComplete;
}
public void setDoAfterComplete(String doAfterComplete) {
this.doAfterComplete = doAfterComplete;
}
}
다른 곳에서 나는 이것을하고 싶습니다.
...
UserDefinedAction udAction = new UserDefinedAction();
udAction.setOnCompleteAction(new ArrayList<UserDefinedAction>());
나는 UserDefinedAction
은 바로 연장하기 때문에 Action
입니까?
그래서 나는 그것을 해결하기 위해이 메소드를 오버라이드 (override) 할 필요가? –
당신은'List extends Action>'대신에 ...'private List extends Action> onCompleteActions; ' – StormeHawke
재정의가 도움이되지 않습니다. 매개 변수의 유형이 변경되기 때문입니다. 이 문제를 해결하려면'List'에서'Action'을 대체하기 위해 제한된 제네릭 형식 매개 변수를 정의하기 위해 제네릭을 사용해야합니다. –
rgettman