* <p>Note that the ordering maintained by a set(whether or not an explicit * comparator is provided) must be <i>consistent with equals</i> if it is to * correctly implement the {@code Set} interface. (See {@code Comparable} * or {@code Comparator} for a precise definition of <i>consistent with * equals</i>.) This is so because the {@code Set} interfaceis defined in * terms of the {@code equals} operation, but a {@code TreeSet} instance * performs all element comparisons using its {@code compareTo} (or * {@code compare}) method, so two elements that are deemed equal by this method * are, from the standpoint of the set, equal. The behavior of a set * <i>is</i> well-defined even if its ordering is inconsistent with equals; it * just fails to obey the general contract of the {@code Set} interface. //翻译 注意,如果要正确实现 Set 接口,则 set 维护的顺序(无论是否提供了显式比较器)必须与 equals 一致。 (关于与 equals 一致 的精确定义,请参阅 Comparable 或 Comparator。)这是因为 Set 接口是按照 equals 操作定义的,但 TreeSet 实例使用它的 compareTo(或 compare)方法对所有元素进行比较 ,因此从 set 的观点来看,此方法认为相等的两个元素就是相等的。即使 set 的顺序与 equals 不一致, 其行为也是 定义良好的;它只是违背了 Set 接口的常规协定。