Why does ConcurrentSkipListSet.contains require a comparator and not equal

I use ConcurrentSkipListSet and uses the contains method.

According to JAVA doc for contains a method

Returns true if this set contains the specified element. More formally returns true if and only if this set contains an element e such that o.equals (e).

But, as in my test, it seems that the equals method is not used, but the Comparator is required. Please help me understand this anomaly between the JAVA specification and the implementation.

ConcurrentSkipListSet

/ ** * If you are using a comparator, return ComparableUsingComparator, else * the cast key as Comparable, which can throw a ClassCastException,    *, which is passed back to the caller. * / private Comparable comparable (Object key)

in java.util.concurrent.ConcurrentSkipListMap.comparable (ConcurrentSkipListMap.java:663) in java.util.concurrent.ConcurrentSkipListMap.doGet (ConcurrentSkipListMap.java:821ConcurpcurrentSaprent.concurrentapcurrentaprerentsconrentcurprent.conrentcurprerent )

I am using Oracle JDK 7

+4
source share
1 answer

, /: (1) Comparator Comparable. (2) Javadoc , equals.

  • ConcurrentSkipListSet - , , .
  • , , , . CSLS ConcurrentSkipListMap.containsKey, . , , , javadocs.

EDIT: throws doc ,

ClassCastException - ,

+2

All Articles