我正在尝试编写一个类:
public class Article<T<? extends ManageGenericArticleInDTO>, U> implements Serializable {
private T<? extends ManageGenericArticleInDTO> userInput;
private U severData;
public Article<T<? extends ManageGenericArticleInDTO>, U>() {
super();
}
public void setUserInput(T<? extends ManageGenericArticleInDTO> userInput) {
this.userInput = userInput;
}
public T<? extends ManageGenericArticleInDTO> getUserInput() {
return userInput;
}
public void setSeverData(U severData) {
this.severData = severData;
}
public U getSeverData() {
return severData;
}
}
这样我就可以写这些:
Article<UpdateManageArticleInDTO<ManageGenericArticleInDTO>, UpdateCentralPOSMArticleDTO> article = new Article<UpdateManageArticleInDTO<ManageGenericArticleInDTO>, UpdateCentralPOSMArticleDTO>();
Article<AddManageArticleInDTO<ManageCentralPOSMArticleInDTO>, AddArticleStepDTO> article = new Article<AddManageArticleInDTO<ManageCentralPOSMArticleInDTO>, AddArticleStepDTO>(); // ManageCentralPOSMArticleInDTO extends ManageGenericArticleInDTO
我收到编译错误Error(7,32): > expected
,Error(7,33): illegal start of type
等等。据我了解,类型引用将被实际类替换。我不能在其中定义类吗?
如果我这样做:
public class AddArticleInBean<T, U> implements Serializable {
private T userInput;
private U severData;
public AddArticleInBean() {
super();
}
public void setUserInput(T userInput) {
this.userInput = userInput;
}
public T getUserInput() {
return userInput;
}
public void setSeverData(U severData) {
this.severData = severData;
}
public U getSeverData() {
return severData;
}
}
此错误不再出现,但我收到 T 和 U 不可序列化的警告。