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

Doug Lea dl at cs.oswego.edu
Fri Sep 2 13:03:46 EDT 2005


Rémi Forax wrote:
> 
>    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
>      else
>        // 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}.
> 

According to this, it seems that you do not want any interface to
ever inherit from Sorted{Set,Map}. So even if we changed Navigable
to not inherit Sorted, someone else will someday cause you the
same problem. Whenever you use instanceof in this way, you are
committing yourself to change your code in the future. (You never know
exactly when or why though -- if you did, you probably wouldn't have
used instanceof.)

Sorry to make your life more complicated, but we won't be changing this.

-Doug










More information about the Concurrency-interest mailing list