Given the following class and service level signatures:
public class PersonActionRequest {
PersonVO person
}
public class MyServiceLayerClass {
public void requestAction(PersonActionRequest request)
{
PersonVO abstractPerson = request.getPerson();
}
private void executeAction(PersonVO person) {}
private void executeAction(EmployeeVO employee) {}
private void executeAction(ManagerVO manager) {}
private void executeAction(UnicornWranglerVO unicornWrangler) {}
}
As discussed here , java will choose the best method based on type information at compile time. (That is, he will always choose executeAction(PersonVO person)).
What is the most suitable way to choose the right method?
On the Internet it is reported that use instanceofallows me to hit. However, I do not see a suitable way to select a method without explicit casting abstractPersonto one of the other specific types.
: - VO - ValueObject, - . , .
personVO.executeAction() .