Primitive streams and optional
Remi Forax
forax at univ-mlv.fr
Sat Nov 24 14:28:10 PST 2012
On 11/24/2012 10:41 PM, Brian Goetz wrote:
> Also, what's the corresponding proposal for primitive streams? I would hate to force boxing onto users of:
>
> Integer x = intStream.filter(...).findFirst();
>
> just because we don't have an int sentinal we can use.
the main issue with this code is that people can write
int x = intStream.filter(...).findFirst();
a will get a NPE without knowing why.
> If we're going to do this to people, we might as well give them a null-safe box (OptionalInt) rather than an accident waiting to happen.
I prefer
int x = intStream.filter(...).findFirst(() -> 0);
or
int x = intStream.filter(...).findFirst(() -> throw new
WeAreInTroubleException());
Rémi
More information about the lambda-libs-spec-observers
mailing list