Inheritance in java collection interfaces

collections, interface, java

Solution

See in java.util.List

"The List interface places additional stipulations, beyond those specified in the Collection interface, on the contracts of the iterator, add, remove, equals, and hashCode methods. Declarations for other inherited methods are also included here for convenience."

Problem

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?

Original source