Reputation: 2252
Spliterator OfPrimitive interface has definition as follow:
public interface OfPrimitive<T, T_CONS, T_SPLITR extends Spliterator.OfPrimitive<T, T_CONS, T_SPLITR>>
extends Spliterator<T> {
@Override
T_SPLITR trySplit();
/**
* If a remaining element exists, performs the given action on it,
* returning {@code true}; else returns {@code false}. If this
* Spliterator is {@link #ORDERED} the action is performed on the
* next element in encounter order. Exceptions thrown by the
* action are relayed to the caller.
*
* @param action The action
* @return {@code false} if no remaining elements existed
* upon entry to this method, else {@code true}.
* @throws NullPointerException if the specified action is null
*/
@SuppressWarnings("overloads")
boolean tryAdvance(T_CONS action);
.....
}
In child interface we have:
public interface OfInt extends OfPrimitive<Integer, IntConsumer, OfInt> {
@Override
OfInt trySplit();
@Override
boolean tryAdvance(IntConsumer action);
.....
}
Why tryAdvance
with same signature is overridden in child interface?
I know sometime for documenting api specification or changing specification in child interface we can override parent interface method, but here there is no change in tryAdvance specification and there is no document on top of that in child interface so why this method is overriden?
Upvotes: 4
Views: 143
Reputation: 49606
It's not really the same signature. The child interface brings the type parameters, and redefines the rather sketchy signature of the parent's methods. You are not obliged to do that, but I see it as a nice way to make the API more readable and even more clearly stated.
Given the fact that the child implements some methods, to me it's important to list the rest of them to emphasise that those are actually to be defined.
A more practical reason would be to help document things. You can't say
{@link #tryAdvance(java.util.function.IntConsumer)}
unless there is an explicitly defined method
@Override
boolean tryAdvance(IntConsumer action);
Note that tryAdvance
, defined in the child, refers to the concrete signature:
/**
* {@inheritDoc}
* @implSpec
* If the action is an instance of {@code IntConsumer} then it is cast
* to {@code IntConsumer} and passed to
* {@link #tryAdvance(java.util.function.IntConsumer)}; otherwise
* the action is adapted to an instance of {@code IntConsumer}, by
* boxing the argument of {@code IntConsumer}, and then passed to
* {@link #tryAdvance(java.util.function.IntConsumer)}.
*/
@Override
default boolean tryAdvance(Consumer<? super Integer> action)
Upvotes: 2