java - Why does NavigableSet (which extends SortedSet) declare subSet(E fromElement, E toElement) again? -


the interface navigableset<e> extends interface sortedset<e> declares method sortedset<e> subset(e fromelement, e toelement) . however, when @ navigableset's api, see has declared same method (with same signature). see says inherits methods (first, last, comparable) sortedset.

since definition, interfaces contain method signatures, why child interface redeclare same method parent interface has declared (and there's no difference in semantics, in api javadoc)?

edit: came across relevant , nice discussion here - in java when 1 interface extends another, why 1 redeclare method in subinterface?

doing allowed in java.

here source code:

/**  * {@inheritdoc}  *  * equivalent {@code subset(fromelement, true, toelement, false)}.  */ public sortedset<e> subset(e fromelement, e toelement) 

perhaps author of class found worthwhile repeat definition because there second definition of subset returns navigableset, having both show side-by-side in javadoc listing nicer having 1 in main method listing , 1 in "inherited" section.

there surely no reason first , last, not done.

here rationale javadocs adding second versions of subset, headset, , tailset:

methods subset(e, e), headset(e), , tailset(e) specified return sortedset allow existing implementations of sortedset compatibly retrofitted implement navigableset, extensions , implementations of interface encouraged override these methods return navigableset.

you might wish try own experiment, designing couple of interfaces, 1 inheriting another, subinterface adding new version of inherited method, see if respecification necessary. :-)


Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -