I have these three interfaces in my code:
public interface ParentInterface {
// some properties and methods
}
public interface ChildOne extends ParentInterface{
//some extra properties and methods
}
public interface ChildTwo extends ParentInterface{
//some extra properties and methods
}
I have some function void someFunc(List<ParentInterface>)
, which should be able to accept hybrid lists with instances implementing either ChildOne
or ChildTwo
. But what if I have a List<ChildOne>
? is there a better way to call someFunc
than this one ?
List<ChildOne> coList = new HashList<ChildOne>();
//add some items to coList
List<ParentInterface> piList = new HashList<ParentInterface>(coList.size());
piList.addAll(coList);
someFunc(piList);
Can't I just make the call like this someFunc(coList)
without having to create a new list ?