I need to create multiple constructors with same arguments so that I can call these from my DAO class for populating different drop down values
public static Employee empType(String empCode, String empType) {
Employee emp = new Employee();
emp .empCode= empCode;
emp .empType= empType;
return emp ;
}
public static Employee empDept(String deptCode, String deptName) {
Employee emp = new Employee();
emp .deptCode= deptCode;
emp .deptName= deptName;
return emp ;
}
When I am referencing from DAO class, how can I refer to these constructors?
E.g.
private static Employee myList(ResultSet resultSet) throws SQLException {
return new <what should be here>((resultSet.getString("DB_NAME1")),
(resultSet.getString("DB_NAME2")));
}
You cant. Also, these functions aren't constructors. And how do you want to decide which "constructor" to call???
You can merge both functions:
public static Employee createEmp(String empCode, String empType, String deptName) {
Employee emp = new Employee();
emp .empCode= empCode;
emp .empType= empType;
emp .deptName= deptName;
return emp ;
}
And use null
as the unneeded argument.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With