Just looking Java Collections and I see the List interface, which extends the Collection interface, also contains the exact same method signatures in the Collection interface -- but not all of them just a subset. My question is why? Since it extends it, we know it will inherit them all by default. And why a subset?
The same can be seen with the Deque extending the Queue, containing all the method signatures of the Queue. Doesn't this make it harder to know what's unique about that interface?
Here is a simple example of the above:
public interface A {
void someMethod();
}
public interface B extends A {
void someMethod(); // why make this explicit?
void anotherMethod();
}
CodePudding user response:
General
In general there is no reason to write out the methods you already get from the other interface again. Do not do that.
Javadoc
In case of Deque
however, it is to override the Javadoc, giving more details that are specific to Deque
and not to general Queue
s.
add(E)
Compare the source code, example add
:
(diff created by P4Merge)
So when you use Deque
s add
method, you will see another Javadoc than when just using the add
method of another Queue
.