I have for example an Interface A and B. A has an (abstract) method called foo. B extends A.
It is possible to override foo in the interface B even with @Override, but is there any situation where that makes sense? There is nothing to override, because both methods have to be abstract and have no body. So I guess there is no situation where this makes sense, right?
So why is it possible to override in an interface?
One situation is when you want to update the Javadoc documentation to reflect a more specific contract in the method in the subinterface, as is the case with Collection#addAll(Collection)
and List#addAll(Collection)
:
Collection#addAll(Collection)
:
Adds all of the elements in the specified collection to this collection (optional operation)...
List#addAll(Collection
:
Appends all of the elements in the specified collection to the end of this list, in the order that they are returned by the specified collection's iterator (optional operation)...
A subinterface can also add a default implementation starting Java 8.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments