In the subclassification, AbstractCollectionI still have to implement it size(), although (I suppose) there is a correct (albeit inefficient) default implementation that is reasonable :
public int size() {
int count = 0;
for (Iterator<E> i = iterator(); i.hasNext();) {
i.next();
count++
}
return count;
}
Why didn't designers include a standard implementation size()? Were they trying to get developers to consciously think about this method, hoping that the developer would suggest an implementation that works better than the default?
source
share