Difference between "implements" and "All Implemented Interfaces" in Java API

Mika2019 :

the Java-API tells me which Interfaces a specific class implements. But there are two different kinds of information and I'm not quite sure what that means. For example for the class "TreeSet" : https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/TreeSet.html there is this information:

All Implemented Interfaces:
Serializable, Cloneable, Iterable<E>, Collection<E>, NavigableSet<E>,     Set<E>, SortedSet<E> 

and also:

public class TreeSet<E>
extends AbstractSet<E>
implements NavigableSet<E>, Cloneable, Serializable

Now, under "implements" there are listed fewer interfaces then under "All Implemented Interfaces". What does that mean?

And further: Say I want to draw an UML-Diagram which specifies the relationship between Treeset and Set and Collection. I assume Treeset implements Set and Collection (because the API says so, but it is not listed under implements which confuses me a little...?). But at the same time Set is also a Subinterface of Collection. So would it be sufficient to draw the arrow that indicates the relation between the two interfaces and than one arrow to indicate that TreeSet implements Set (but no arrow to Collection) or would I need to draw an arrow indicating that TreeSet implements Collection aswell?

Sorry for my english. I hope I could make my question understandable.

Eran :

implements lists the directly implemented interfaces, which are the interfaces explicitly specified in the implements clause`.

The list of all implemented interfaces can be longer, since the interfaces that the class implements directly can extend other interfaces, which the class implements indirectly.

TreeSet directly implements NavigableSet, but since NavigableSet extends SortedSet, which extends Set, which extends Collection, which extends Iterable , all of those interfaces are implemented indirectly by TreeSet, which is why they are listed in the list of all implemented interfaces.

As for the UML diagram, I'd draw an arrow that indicates "implements" only between a class and the interfaces it directly implements. The indirectly implemented interfaces will be shown in the hierarchy of the directly implemented interfaces.

For example:

Iterable
  ^
  |
Collection
  ^
  |
 Set
  ^
  |
SortedSet
  ^
  |
NavigableSet
  ^
  |
TreeSet

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=114545&siteId=1