Nulls

Doug Lea dl at cs.oswego.edu
Sun Sep 23 06:12:00 PDT 2012


On 09/23/12 08:38, Tim Peierls wrote:
> On Sun, Sep 23, 2012 at 8:07 AM, Doug Lea <dl at cs.oswego.edu
> <mailto:dl at cs.oswego.edu>> wrote:
>
>     The main downside is that findAny is forced to lie (reporting absent) if a
>     null item matches predicate.
>
>
> Doesn't bother me.

It encounters the same antipattern seen when you
need to establish that a Map key has no mapping:
  if (map.get(k) == null)     // don't know if there is a mapping
     if (!map.containsKey(k)) // so recheck
Which might not seem so terrible in particular cases where
you are prepared to cope with mappings to null. But the
issues make it impossible to write some generic
Map utilities because the need to recheck forces non-atomicity.

For findAny etc, the issue is even harder:
   if (!...findAny(...).isPresent())
     // somehow recheck?
And the need for recheck is even less obvious.


-Doug



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