Sì, questo è ciò che l'operazione flatMap
è per:
List<InstitutionUserConnection> allInstitutionUserConnections =
institutionsOfUser.stream()
.flatMap(institution -> institutionUserConnectionService.getActiveInstitutionUserConnectionsByInstitution(institution).stream())
.collect(Collectors.toList());
Se il metodo genera un'eccezione verificata, allora avete bisogno di prenderlo e gestirlo con la registrazione, rethrowing un'eccezione incontrollata e/o restituire un valore predefinito.
List<InstitutionUserConnection> allInstitutionUserConnections =
institutionsOfUser.stream()
.flatMap(institution -> {
try {
return institutionUserConnectionService.getActiveInstitutionUserConnectionsByInstitution(institution).stream();
} catch (TheCheckedThrownException e) {
// do something here, like throw an unchecked exception
}
})
.collect(Collectors.toList());
institutionUserConnectionService.getActiveInstitutionUserConnectionsByInstitution (istituzione) genera un'eccezione. C'è anche la possibilità di gestirlo? Molte grazie! – quma
@ user3318489 Sì, vedere la mia modifica. – Tunaki