Given:
interface ViewableDTO {//methods here}
class PersonDTO implements ViewableDTO {//implementation here}
This works fine:
PersonDTO p = new PersonDTO();
ViewableDTO v = p; //works
How come this doesn't work:
List<PersonDTO> plist = getPersonDtoList();
List<ViewableDTO> vlist = plist; //compilation error
List<ViewableDTO> vlist = (List<ViewableDTO>)plist; //compilation error
My solution here is to do this:
List<ViewableDTO> vlist = new ArrayList<ViewableDTO>();
vlist.addAll(plist);
My question is, is this the only / best way to do it?