What is the best/idiomatic way of doing a null check before getting a stream?
I have method that is receiving a List
that might be null. So I can\'t jus
Personally I consider null deprecated and use Optional wherever possible despite the (tiny) performance overhead. So I use the interface from Stuart Marks with an implementation based on gdejohn, i.e.
@SuppressWarnings("unchecked")
static Stream nullableCollectionToStream(Collection extends T> coll)
{
return (Stream) Optional.ofNullable(coll)
.map(Collection::stream)
.orElseGet(Stream::empty);
}