Overriding a default method
"Zdeněk Troníček"
tronicek at fit.cvut.cz
Thu Aug 9 07:56:12 PDT 2012
Hi,
if a new method is added to an existing interface in JDK 8, e.g. skip() to
Iterator:
public interface Iterator<E> {
boolean hasNext();
E next();
void remove();
void skip(int i) default {
for (; i > 0 && hasNext(); i--) next();
}
}
it may happen that existing implementations have already a method of the
same name. This method overrides the default method which is ok if it is
intentional. However, unintentional overriding may lead to severe bugs
when the method has different semantics.
Do you plan to emit a warning at compile time, for example, when a class
overrides a default method and @Override is missing?
Z.
--
Zdenek Tronicek
FIT CTU in Prague
More information about the lambda-dev
mailing list