Inheritance in java collection interfaces

Viewed 3057

There are some inheritance relationship in Java collection interfaces. For example, Collection<T> interface will extend Iterable<T>. I checked the source code in JDK, some methods defined in base class get repeated in sub classes several times. For example: Interable<T> interface defined a method Iterator<E> iterator(); But in interface Collection<E> and List<T>, also contain the same method. In my understanding, since inheritance is used to reduce duplication, why should we define the same method in subclasses?

4 Answers
Related