I have the next problem with inheritance in Objects:
-First Class:
public class LegalPersonRest extends LegalPerson {}
-Second Class:
public class Company {
private List<LegalPerson> legalPersons;
}
-Third Class:
public class CompanyRest extends Company {
@Override
public List<LegalPersonRest> getLegalPersons() {
return super.getLegalPersons();
}
}
In this method getLegalPersons I got the error: attempting to use incompatible return type.
I don't know why if LegalPersonRest extends LegalPerson.
The classes Company and LegalPerson are my domain. (layer domain)
The classes CompanyRest and LegalPersonRest extends the classes of the domain. (layer adapter)
If I change of List to List, I think is wrong because I need used LegalPersonRest.
What's the correct form of inheritance for this case?
Regards,