Object的equals方法

1. equals是类的实例方法。

2.方法翻译

public boolean equals(Object obj)
Indicates whether some other object is "equal to" this one.

(句子结构:动宾,宾语由whether引导的名词从句充当。some other + 可数名词单数,译为某一事物。)

指示了某一对象与这个对象是否相等。


The equals method implements an equivalence relation on non-null object references:

equals方法实现了关于非空对象引用的一种等价关系。

  • It is reflexive: for any non-null reference value xx.equals(x) should return true.
  • 它是反身的:对于任何非空引用值x, x.equals(x)应该返回ture。
  • It is symmetric: for any non-null reference values x and yx.equals(y) should return true if and only if y.equals(x) returns true.
  • 它是对称的: 对于任何非空引用值x和y, 当且仅当y.equals(x)返回true时,x.equals(y)应该返回true。
  • It is transitive: for any non-null reference values xy, and z, if x.equals(y) returns true and y.equals(z) returns true, thenx.equals(z) should return true.
  • 它是传递的: 对于任何非空引用值x,y,和z,如果x.equals(y)返回true,y.equals(z)返回true,那么x.equals(z)应该返回true。
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • 它是一致的:对于任何非空引用值x和y,x.equals(y)的多次调用总是返回true或总是返回false,不提供修改使用于对象的equals比较的信息。
  • For any non-null reference value xx.equals(null) should return false.
  • 对于任何非空引用值x,x.equals(null)应该返回false。

The equals method for class Object implements the most discriminating possible equivalence relation on objects; that is, for any non-null reference values x and y, this method returns true if and only if x and y refer to the same object (x == y has the value true).

类Object的equlas方法,实现了关于对象的最有区别的可能等价关系;即,对于任何非空引用值x和y,当且仅当x和y引用同一个对象时(x == y得到值true),这个方法返回true。

Note that it is generally necessary to override the hashCode method whenever this method is overridden, so as to maintain the general contract for the hashCode method, which states that equal objects must have equal hash codes.

注意,无论何时这个方法被重写,一般需要重写hashCode方法,为了保持与hashCode方法通用一致,这样做就规定了相等的对象必须有相等的散列码。

Parameters: 形参
obj - the reference object with which to compare.参与比较的引用对象。
Returns: 返回
true if this object is the same as the obj argument;  false otherwise.如果这个对象与obj参数相同返回true,否则返回false。


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值