您好我基本上收到一条错误消息,
constructor Member in class Member cannot be applied to given types;
required: java.lang.String,java.lang.String; found:java.lang.String;
reason: actual and formal argument lists differ in length
但我不知道为什么,我想也许可能是因为我不允许在构造函数中传递多个超级调用?这是对的吗?
这是我的超级班,其中包含姓名和电子邮件
public class Member
{
// The teacher's or Student's name.
private String name;
// The teacher's or Student's email;
private String email;
/**
* Constructor for objects of class Member
*/
public Member(String name,String emailID)
{
this.name = name;
email = emailID;
}
}
这是子类的构造函数,当我尝试编译时,我得到了错误。
public Student(String name, String emailID)
{
super(name);
super(emailID);
attendance = 0;
}
根据我的理解,这应该可以正常工作,但事实并非如此,是否有人可以解释为什么这不起作用?
由于
答案 0 :(得分:1)
它不起作用,因为超类需要两个参数,但你只是逐个提供它们,所以第一个构造函数super(name);
无法编译,这就是为什么会出现这样的错误存在。所以你应该像这样把它们放在一起:
super(name, emailID);
编辑:此外,你只能调用超级构造函数一次,它应该首先调用它。
答案 1 :(得分:1)
尝试这样称呼:
@GET
@Produces({"application/xml", "application/json", "application/vnd.ms-excel"})
@Path("/export")
@Override
public void getStream(@QueryParam("names") List<String> names,@Context HttpServletResponse response) {
try {
XSSFWorkbook workbook = getData(articleTypeCodes);
response.setHeader("Content-Disposition", "attachment; filename=template.xlsx");
response.getOutputStream().write(convertWorkbookToOutputStream(workbook));
response.flushBuffer();
} catch (ManagerException | IOException ex) {
throwException(ex);
}
}