You may use toCollection(Supplier)
:
return ALL_OPTS.stream().filter(a -> (a.ameityId & bitFlag) > 0)
.collect(Collectors.toCollection(() -> EnumSet.noneOf(Amenities.class)));
The toCollection
method receives a lambda which should create an empty collection to store the result. Here we create empty EnumSet
using EnumSet.noneOf
call. Note that for EnumSet
you must always specify (implicitly or explicitly) which enum is this set for.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…