Sized

Kevin Bourrillion kevinb at google.com
Fri Nov 2 15:27:29 PDT 2012


My mistake: CHM only has to walk through every *segment* to add up the
size, and I was thinking of it as actually traversing every element.

In any event. It's undeniably true that there are numerous implementations
of Collection out there that don't know their size without completely
iterating themselves. I still say that if there's any value in Sized, it
lies in making those implementations *not* implement it while others do.



On Fri, Nov 2, 2012 at 3:22 PM, Brian Goetz <brian.goetz at oracle.com> wrote:

>  Of course, some collections, like the key set of a ConcurrentHashMap,
>> don't know their size any more than a garden-variety Iterable does.
>>
>
> That's not exactly true.  In the absence of interference from concurrent
> modification, the key set of a CHM absolutely knows its size.  It's just
> that in the presence of interference, the reported size may be stale by the
> time you receive it.
>



-- 
Kevin Bourrillion | Java Librarian | Google, Inc. | kevinb at google.com


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