Reputation: 69
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.
Upvotes: 3
Views: 361
Reputation: 393946
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
Upvotes: 5
Reputation: 327
The "All Implemented Interfaces" list is nothing but the list interfaces which TreeSet class implements internally. You can always verify this by opening source code in your IDE (Eclipse, STS etc.), if you are using Eclipse IDE I would suggest you to open TreeSet interface in your IDE and verify this.
public class TreeSet<E> extends AbstractSet<E>
implements NavigableSet<E>, Cloneable, java.io.Serializable
{}
Upvotes: 0
Reputation: 45329
"All implemented interfaces" includes those implemented by superclasses or extended by implemented interfaces (directly or not).
Here's the view given by Eclipse's type hierarchy, which shows you where the other interfaces are added:
Upvotes: 1
Reputation: 12268
The "All Implemented Interfaces" list is telling you the interfaces that the class implements directly, plus all of the interfaces that those interfaces are derived from. So, for example, NavigableSet
is derived from Set
. TreeSet
does not implement Set
directly, but Set
is implemented via the fact that anyone who implements NavigableSet
also implements Set
.
Upvotes: 1