Is there way to collect()
generic items from a stream
?
This is what I want to do...
private <T extends Data> List<Response<T>> validateAndGetResponses(List<Response> responses, Class<T> clazz) {
Supplier<List<Response<T>>> supplier = LinkedList::new;
List<Response<T>> list = responses.stream().filter(
response -> clazz.isInstance(getData(response))).collect(Collectors.toCollection(supplier));
return list;
}
This doesn't work, I get
no suitable method found for collect(....)