Primitive streams and optional

Doug Lea dl at cs.oswego.edu
Wed Nov 28 07:27:11 PST 2012


On 11/26/12 15:43, Brian Goetz wrote:

> 1.  Ban nulls.  This is equivalent to adding
>     .tee(e -> { if (e == null) throw new NPE(); }
> between all stages of a pipeline.
>
> 2.  Ignore nulls.  This is what Doug is proposing, and is equivalent to adding
>     .filter(e -> e != null)
> between all stages of a pipeline.
>
> 3.  Tolerate nulls.  This treat nulls as "just another value" and hopes that
> lambdas and downstream stages can deal.
>

In case anyone was thinking that these have anything to do with
efficiency, remember that JVMs are required to null-check each
non-explicity-checked use of any reference anyway.
So these three choices have similar costs.

(They do vary a little:  #3 will sometimes be the most expensive,
since the lack of a pre-null-check forces twistier code paths
to be generated later on first dereference of a field.)

-Doug




More information about the lambda-libs-spec-observers mailing list