Reputation: 908
A Java class implementing SortedSet is supposed to provide an iterator that iterates its elements in ascending order, in addition to some other methods. But I see no way that the SortedSet interface specification enforces this behavioral constraint that it specifies. SortedSet just has a few methods that an implementing class can implement without actually having to comply with the requirement of returning an ascending iterator, or indeed of having a valid comparator.
Just looking at the interface methods without knowing its name would not tell the developer the core behavior implementing classes are supposed to implement.
Is the implementing developer supposed to read the Javadoc and follow the specification to implement correctly ? Isn't SortedSet supposed to ensure that implementing classes actually return an ascending iterator .. What is the point of that interface otherwise?
Upvotes: 1
Views: 62
Reputation: 72864
An interface typically acts as a contract or a blueprint, that an implementation will conform to. The purpose of SortedSet
is really to provide a standard interface for sorted sets that code can use, while allowing to switch the implementation (for example to a more performant one).
So the answer is yes the implementation must conform to the Javadocs which formally document the contract. Any implementation that does not do follow the documented behavior is simply considered a buggy one.
Upvotes: 1