我遇到了一个问题,我的代码将登录表单链接到我的csr表单,以将员工重定向到正确的表单。我有一个Staff类和一个CustomerServiceRep类,CustomerServiceRep扩展到Staff。代码是
//staff object to store staff logged in successfully
Staff emp = null;
/*Use core to store staff logged in should return an staff
object if username/password found OR null if credentials invalid*/
emp = core.login(username, password);
if (emp==null){//staff not found
//display feedback
pop.showMessageDialog(
null,
"Login Credentials Invalid",
"Errors",
JOptionPane.ERROR_MESSAGE
);
}else{//staff found, redirect to dashboard
pop.showMessageDialog(
null,
"Login Successful",
"Feedback",
JOptionPane.INFORMATION_MESSAGE
);
//redirect user to appropriate dashboard
if(emp.getRole().equals("csr")){
//go to csr dash
//hide the login form(current form)
this.setVisible(false);
/**create new instance of AdminDashboard form and
* pass the instance of Staff (emp) who
* has logged in successfully
*/
Z_Frm_CSR CSRDash = new Z_Frm_CSR(emp);
//Show CSR Dashboard
CSRDash.setVisible(true);
}
我收到错误“不兼容的类型:员工无法转换为CustomerServiceRep”为emp
Z_Frm_CSR CSRDash = new Z_Frm_CSR(emp);
我是这个网站的新手,对编码很新,我不知道如果我提供了足够的错误信息,请询问更多信息,如果没有给出。
答案 0 :(得分:0)
您需要进行显式转换,因为您的Z_Frm_CSR构造函数可能在其声明(CustomerServiceRep)中使用显式类型而不是基类(Staff)或通用类型(T扩展Staff)。
所以:exists