Java泛型编译错误-不理解错误

Java泛型编译错误-不理解错误,java,generics,Java,Generics,我知道很多人会问这样的问题,但我真的不明白这个问题 (如果您需要更多代码,请告知) 我还具有向问题库添加问题的功能: manager.addQuestion(question); 但我得到以下两个错误: Incorrect number of arguments for type QuestionManager<Question>; it cannot be parameterized with arguments <? extends Component, IQuestio

我知道很多人会问这样的问题,但我真的不明白这个问题

(如果您需要更多代码,请告知)

我还具有向问题库添加问题的功能:

manager.addQuestion(question);
但我得到以下两个错误:

Incorrect number of arguments for type QuestionManager<Question>; it cannot be parameterized with arguments <? extends Component, IQuestion<? extends IAnswerStorage>>

非常感谢你的帮助。如果您需要更多信息,请告诉我。

在声明变量时,不能在泛型部分使用“&”。它仅在声明泛型类时起作用。声明使用泛型类的变量/字段时,始终为泛型参数提供具体的类/接口。 e、 例如,在这个表达式中,
QuestionManager

public class QuestionManager<Question extends Component & IQuestion<? extends IAnswerStorage>>
QuestionManager<? extends Component & IQuestion<? extends IAnswerStorage>> manager = new AccountingQuestionManager<>("Test test", this);
您试图做的是为
QuestionManager
类型声明一个类型参数。类型参数不能声明为具有多个边界。根据定义,类型参数已经是具有任何边界的类型。不能在表达式中重新定义它


您可以在类声明中使用泛型
&
,但不能在变量赋值中使用。你可以放心地做

QuestionManager<?> manager = //...
QuestionManager=/。。。

因为在类型参数
问题
的规范中保证它已经适合
?扩展Component&IQuestion,这样我就能够解决我的特定问题(如果我不那么通用,我就无法解决)
问题经理:

public class QuestionManager<Question extends IQuestion<? extends AnswerStorage>>

公共课堂问题管理您可以使用
哦,我的天哪。我将修改答案,因为
QuestionManager
什么时候有两个类型参数?我觉得很尴尬。。。我想我应该睡一会儿。谢谢你指出这一点。@Reisi007它怎么不起作用?使用我的解决方案时会遇到什么问题?如果我使用,则addQuestion(问题)的类型为?。我不能从类型“”添加任何内容。感谢您的尝试,但是Java在这方面还不够聪明。不管怎样,我找到了一个有效的解决办法
QuestionManager<? extends Component & IQuestion<? extends IAnswerStorage>> manager = new AccountingQuestionManager<>("Test test", this);
QuestionManager<?> manager = //...
public class QuestionManager<Question extends IQuestion<? extends AnswerStorage>>
public <QuestionComponent extends IQuestion<? extends AnswerStorage> & Component> void addQuestion(
        QuestionComponent question)