Reputation: 1453
I have this List of generics List<? super Domain>
,containing to implementation of Domain: Material and BoM,now I want to get each entity separately.
domainList.stream().filter(a -> a.getClass().equals(BoM.class))
.collect(Collectors.toList());
with this line i have List<? super Domain>
that only contains BoM object.my problem is how to convert this list to List<BoM>
?
Upvotes: 4
Views: 1490
Reputation: 78579
Well, I'd do it like this:
List<BoM> boms = domainList.stream()
.filter(BoM.class::isInstance)
.map(BoM.class::cast)
.collect(Collectors.toList());
Upvotes: 8