I have a method:
private List<ApplicationForVacancy> createListOfApplicationsForVacancy(List<Document> documents) {
return documents.stream()
.filter(d -> d instanceof ApplicationForVacancy)
.map(d -> (ApplicationForVacancy) d)
.collect(Collectors.toList());
}
but I'd like to pass the name of the class/the type of the class in parameter and return type of the method like this:
private List<TypeOfSomeClass> createList (List<Document> documents, String or Type typeOfSomeClass) {
return documents.stream()
.filter(d -> d instanceof typeOfSomeClass)
.map(d -> (typeOfSomeClass) d)
.collect(Collectors.toList());
}
Is it possible? How can I do that?