Nulls

Brian Goetz brian.goetz at oracle.com
Fri Sep 21 09:36:56 PDT 2012


But this leaves us with now three ways of saying "no value"

  - reference to Optional is null
  - Optional is empty
  - Optional is not empty but contains null

And this just kicks the NPE can down the street.

On 9/21/2012 12:35 PM, Joe Bowbeer wrote:
>
>  > I agree, so this is where the strong force meets the heavy object.
>
> The null penetrates the Optional?
>
>
> On Fri, Sep 21, 2012 at 9:30 AM, Brian Goetz <brian.goetz at oracle.com
> <mailto:brian.goetz at oracle.com>> wrote:
>
>         If there is this operation:
>
>               Optional<T> findFirst()
>
>         then there should also be a version that takes a Predicate:
>
>               Optional<T> findFirst(Predicate)
>
>
>     We started there and beat a rapid U-turn.
>
>     If you have findFirst(Predicate), you end up reinventing the whole
>     stream protocol either with overloads of find or with other methods
>     on Optional or both, because what if you want to filter and then
>     map?  Do you do firstFirst(Predicate, Mapper)?  There already is
>     filter(Predicate), so having a findFirst(Predicate) is unnecessary.
>
>     If we have filter(Predicate) all the same arguments apply anyway.
>
>
>         But the question really boils down to whether Optional can
>         contain null,
>         and I don't think it should.
>
>
>     I agree, so this is where the strong force meets the heavy object.
>       Do we try to keep the nulls away, or do we treat this as an
>     illegal stream and blow when it gets to findFirst, or do we ignore
>     nulls and treat them as "not there"?
>
>


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