I have this method:
public static <T> List<T> flat(List<T>... lists){
return Stream.of(lists)
.filter(Objects::nonNull)
.flatMap(List::stream)
.collect(toList());
}
The idea is to flat a list of lists and return a list with the same type.
Suppose that A and B extends C. This does not work:
List<A> listOfA;
List<B> listOfB;
List<C> listOfC = flat(listOfA, listOfB);
Because List<A> is not a List<C>!
Anyone know how to write a flat method signature with generics that admits what I'm trying to do?
Thanks!