Nulls
Doug Lea
dl at cs.oswego.edu
Sun Sep 23 06:53:41 PDT 2012
On 09/23/12 09:34, Remi Forax wrote:
> On 09/23/2012 03:12 PM, Doug Lea wrote:
>> 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
>
> yes, for Map, we need a getEntry() but introducing it now as a default method
> will have the same problem that the default implementation is not atomic.
Mostly an aside: Without further guarantees, even getEntry
encounters problems:
Map.Entry e = map.getEntry(k);
// ...
if (e.getValue() == null) // was e removed or is value null?
In j.u.c ConcurrentMaps.entrySet().iterators, that return
Entry objects, we guarantee snapshot semantics, which along with
no-nulls rule, removes this uncertainty. Entry.setValue is
still under-constrained though -- we do write-through, which
revives an entry if had been removed.
-Doug
More information about the lambda-libs-spec-experts
mailing list