Compares its two arguments for order. Returns a negative integer,zero, or a positive integer as the first argument is less than, equal to, or greater than the second.<p>
比较其两个参数的顺序。当第一个参数小于、等于或大于第二个参数时,返回一个负整数、零或正整数。
It is generally the case, but <i>not</i> strictly required that
* <tt>(compare(x, y)==0) == (x.equals(y))</tt>. Generally speaking,
* any comparator that violates this condition should clearly indicate
* this fact. The recommended language is "Note: this comparator
* imposes orderings that are inconsistent with equals."
这是一般情况下,但不会严格要求(compare(x, y)==0) == (x.equals(y))。一般来说,任何违反这个这个状态的构造器都可以很清楚的表明这个事实。语言中要被提醒的是“注意:这个构造器会强制执行与等式不一致的排序”
@FunctionalInterface
public interface Comparator<T> {
int compare(T o1, T o2);
}
Indicates whether some other object is "equal to" this
comparator. This method must obey the general contract of
{@link Object#equals(Object)}. Additionally, this method can return
<tt>true</tt> <i>only</i> if the specified object is also a comparator
and it imposes the same ordering as this comparator. Thus,
<code>comp1.equals(comp2)</code> implies that <tt>sgn(comp1.compare(o1,
o2))==sgn(comp2.compare(o1, o2))</tt> for every object reference
<tt>o1</tt> and <tt>o2</tt>.<p>
判断一些对象是否相等,这个方法必须承认{@link Object#equals(Object)}的惯例用法
另外,这个方法只有在指定的对象也是一个比较器,并且它与这个比较器施加相同的排序的情况下可以返回true
因此,comp1.equals(comp2)也对于每个涉及到o1和o2的对象表示sgn(comp1.compare(o1,o2))==sgn(comp2.compare(o1, o2))
public interface Comparator<T> {
boolean equals(Object obj);
}