[concurrency-interest] Navigable{Map, Set} must not inherit from Sorted{Map, Set}

Rémi Forax forax at univ-mlv.fr
Fri Sep 2 12:28:28 EDT 2005

The problem :
   I have a user defined implementation of a Set
   (FastTraversalSet) and this implementation
   already provides some traversal methods that
   i could use to retrofit the class
   in order to implement NavigableSet interface.
   But i think i can't do this without risking to break
   the semantic of my program.

   Because NavigableSet inherits from SortedSet
   (an interface that already exists in the JDK),
   if i retrofit my class some code in my program
   could have a different behavior :

   void doSomething(Set<String> set) {
     if (set instanceof SortedSet)
       // before retrofitting:
       //   it's a tree set, or a wrapper on a tree set
       //   like unmodifiableSet(...)
       // after retrofitting:
       //   oups FastTraversalSet match
       // it's my implementation

   The fact that NavigableSet inherits from SortedSet
   prevents me to retrofit FastTraversalSet.

   Please, Navigable{Set,Map} must not inherits
   from Sorted{Set,Map}.

Rémi Forax

More information about the Concurrency-interest mailing list