Что означает сравнение с равными? Что может случиться, если мой класс не будет следовать этому принципу?

Из JavaDoc TreeMap:

Note that the ordering maintained by a sorted map (whether or not an explicit comparator is provided) must be consistent with equals if this sorted map is to correctly implement the Map interface. (See Comparable or Comparator for a precise definition of consistent with equals.) This is so because the Map interface is defined in terms of the equals operation, but a map performs all key comparisons using its compareTo (or compare) method, so two keys that are deemed equal by this method are, from the standpoint of the sorted map, equal. The behavior of a sorted map is well-defined even if its ordering is inconsistent with equals; it just fails to obey the general contract of the Map interface.

Может ли кто-нибудь привести конкретный пример, чтобы продемонстрировать проблему, которая может возникнуть, если порядок не соответствует принципу равенства? Возьмем, к примеру, определенный пользователем класс, который имеет естественный порядок, т.е. реализует Comparable. Также все внутренние классы в JDK поддерживают этот инвариант?

Ответы на вопрос(3)

Ваш ответ на вопрос