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

Rémi Forax forax at univ-mlv.fr
Fri Sep 2 14:11:25 EDT 2005


Doug Lea a écrit :
 > 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}.

No, anyone can write an interface that inherit from Sorted{Set,Map}
because i'm free to not use its library.
That not the case of the JDK.
If i want the next Java, i get the new JDK API bundle with it.

 > So even if we changed Navigable
 > to not inherit Sorted, someone else will someday cause you the
 > same problem.

I can choose to not use the library that do this.
I can't do the same with the JDK.

 > 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.)

Yes your right its a "bad design", but i think i have no
way in Java to avoid such code.
Take by example java.util.Collections and count how many instanceof
you can find. I'm not the only one to use such design :)

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

i think it could make not only my life more complicated.

 >
 > -Doug
 >
 >

Rémi




More information about the Concurrency-interest mailing list