Just a quick small snippet on how to convert a Optional to a List.
Hope it helps someone, who's new at Optionals.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public <T> List<T> convert(Optional<T> optT) | |
{ | |
return optT.map(Collections::singletonList) | |
.orElse(Collections.emptyList()); | |
} |
No comments:
Post a Comment