I have a list of ScheduleContainer
objects and in the stream each element should be casted to type ScheduleIntervalContainer
. Is there a way of doing t
Do you mean you want to cast each element?
scheduleIntervalContainersReducedOfSameTimes.stream()
.map(sic -> (ScheduleIntervalContainer) sic)
// now I have a Stream
Or you could use a method reference if you feel it is clearer
.map(ScheduleIntervalContainer.class::cast)
On a performance note; the first example is a non-capturing lambda so it doesn't create any garbage, but the second example is a capturing lambda so could create an object each time it is classed.