RFR 8005704: Update ConcurrentHashMap to v8

Doug Lea dl at cs.oswego.edu
Wed May 29 13:18:58 UTC 2013

On 05/28/13 16:03, Martin Buchholz wrote:
> A long-returning size method seems like a framework-level decision.  We could
> add a default method to Collection.java and Map.java
> default long mappingCount() { return size(); }

The lambda EG discussed this, and decided not to do it now,
and to put off support for 64bit collections until JDK9.
But CHM needs this now, so we picked a name that is usable
but not likely to clash with some better future name, like length().


> I'm not sure mappingCount is the best name, but all names will be confusing.
>   Using the name "length()" at least has an onomatopoeic mnemonic advantage - it
> suggests that it might return a long.
>      /**
>       * Returns the number of mappings. This method should be used
>       * instead of {@link #size} because a ConcurrentHashMap may
>       * contain more mappings than can be represented as an int. The
>       * value returned is an estimate; the actual count may differ if
>       * there are concurrent insertions or removals.
>       *
>       * @return the number of mappings
>       */
>      public long mappingCount() {
>          long n = sumCount();
>          return (n < 0L) ? 0L : n; // ignore transient negative values
>      }

More information about the core-libs-dev mailing list