Sized

Brian Goetz brian.goetz at oracle.com
Tue Nov 27 19:56:57 PST 2012


Never mind, dumb question.

On 11/27/2012 10:46 PM, Brian Goetz wrote:
>> I still think the only way out is to introduce a new method
>> with long return type. We could even do it while keeping the name
>> Sized, but leaving the size() method alone for continued use in
>> Collections-only applications, and defaulting the new method in
>> Collection:
>
> OK, but...
>
>> public interface Sized { // or pick a new name
>>      /**
>>       * Returns the number of elements
>>       */
>>      long elementCount(); // oh no, another arbitrary name choice
>>
>>      default boolean isEmpty() { return elementCount() == 0; }
>> }
>>
>> interface Collection<E> extends Sized ... {
>>    default long elementCount() { return (long)size(); }
>>    ...
>> }
>
> ...why would you have the new method not return the actual size, rather
> than the clamped size returned by size()?
>


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