ChildDto extends BaseDto , and here I am sure that its list is populated by ChildDto .
Then why does the argument type of this method not represent this knowledge?
Should it be List<ChildDto> or even List<? extends ChildDto> List<? extends ChildDto> .
How you do this is one solution, you can also use each return value yourself. Both are equally good at failing in roughly the same position:
for (BaseDto bDto : list) 7 ChildDto dto = (ChildDto) bDto;
source share