源码中comparator<T>的部分翻译

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 &quot;equal to&quot; 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);

}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值