I have class Employee and 3 classes that extends Employee class.
I also have EmployeeService interface where i want to have only one save method to handle saving each type of Employee. So i assumed that it could be solved using generics.
This is what i tried in EmployeeService interface:
public interface EmployeeService {
<SubRequestT extends Employee>EmployeeResponse save(SubRequestT requestT);
}
And class that provide implementation:
@Service
public class EmployeeServiceImpl implements EmployeeService {
// So here in argument i want to have to put any kind of Employee, for example:
@Override
public EmployeeResponse save(OfficeEmployee requestT) {
// Logic for saving employee
return null;
}
}
But when i changed from Employee type to any other, for example OfficeEmployee who is extending from Employee, complier is giving me an error. What is best way to solve this?