Minimum complete definition of Collection
interface consists only of two methods: iterator()
and size()
, which are abstract in AbstractCollection
.
Why all other methods not made default in Java 8? Compatibility shouldn't be an issue, for example, Iterator.remove()
was abstract until Java 7, but made default since Java 8.
Subclassing from AbstractCollection
is inconvenient sometimes, when I want a Collection
implementation to be a member of another class hierarchy. Wasn't that one of the reasons why default methods in interfaces actually needed in Java?
The same question about Map
, List
and other basic interfaces, comprising Java Collection Framework.
UPDATE
Paul Sandoz:
Generally we have only converted existing abstract methods on an interface to non-abstract if there was a compelling reason to aid implementations, such as Iterator.remove.
These are not new methods on Collection, and there are already implementations in AbstractCollection. The advantage of converting these abstract into non-abstract methods its not particularly compelling given one is most likely to inherit from AbstractCollection or provide more efficient implementations.
It would be possible to move all non-abstract methods on AbstractCollection to Collection. If we were starting from a blank sheet of paper that is what we might have done. (Note one cannot do this with all non-abstract methods on AbstractList.)
http://mail.openjdk.java.net/pipermail/core-libs-dev/2014-February/025118.html