Question about java.util.Set

Z

Zhao

I noticed that java.util.Set extends java.util.Collection and
all the abstract methods of Collection is redeclare in java.util.Set.

Why? It is not necessary since java.util.Set inheritant all this methods
already, why do we need to redeclare them? Similar codes appear in other
Collection interfaces like List.

thanks

Zhao
 
M

Michael Borgwardt

Zhao said:
I noticed that java.util.Set extends java.util.Collection and
all the abstract methods of Collection is redeclare in java.util.Set.

Why? It is not necessary since java.util.Set inheritant all this methods
already, why do we need to redeclare them? Similar codes appear in other
Collection interfaces like List.

Indeed this is technically unnecessary but was probably done in order to be
able to give more specific javadoc comments in the derived interfaces.
 
J

John C. Bollinger

Zhao said:
I noticed that java.util.Set extends java.util.Collection and
all the abstract methods of Collection is redeclare in java.util.Set.

Why? It is not necessary since java.util.Set inheritant all this methods
already, why do we need to redeclare them? Similar codes appear in other
Collection interfaces like List.

Michael's response is pretty good, but why not read what Sun itself has
to say about the matter in Set's API docs:

The Set interface places additional stipulations, beyond those inherited
from the Collection interface, on the contracts of all constructors and
on the contracts of the add, equals and hashCode methods. Declarations
for other inherited methods are also included here for convenience. (The
specifications accompanying these declarations have been tailored to the
Set interface, but they do not contain any additional stipulations.)


Similar statements appear in the API docs of the other interfaces of the
collections framework.


John Bollinger
(e-mail address removed)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,679
Members
48,796
Latest member
Greg L.

Latest Threads

Top