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>
?
Well, I'd do it like this:
List<BoM> boms = domainList.stream()
.filter(BoM.class::isInstance)
.map(BoM.class::cast)
.collect(Collectors.toList());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With