No, because generic types are not covariant.
List<BImpl> not a subclass of List<B> .
Part of the method contract in interface A is that it returns a List<B> .
public interface A { List<B> getBs(); }
A List<BImpl> does not support this contract. For example, a recipient expecting List<B> might try to add other types of B to the list instances β for example, BImpl2 and BImpl3 .
A List<B> containing only BImpl will support the contract.
source share