Object

Object类有以下几个方法

equals()

 1 /**
 2      * Indicates whether some other object is "equal to" this one.
 3      * <p>
 4      * The {@code equals} method implements an equivalence relation
 5      * on non-null object references:
 6      * <ul>
 7      * <li>It is <i>reflexive</i>: for any non-null reference value
 8      *     {@code x}, {@code x.equals(x)} should return
 9      *     {@code true}.
10      * <li>It is <i>symmetric</i>: for any non-null reference values
11      *     {@code x} and {@code y}, {@code x.equals(y)}
12      *     should return {@code true} if and only if
13      *     {@code y.equals(x)} returns {@code true}.
14      * <li>It is <i>transitive</i>: for any non-null reference values
15      *     {@code x}, {@code y}, and {@code z}, if
16      *     {@code x.equals(y)} returns {@code true} and
17      *     {@code y.equals(z)} returns {@code true}, then
18      *     {@code x.equals(z)} should return {@code true}.
19      * <li>It is <i>consistent</i>: for any non-null reference values
20      *     {@code x} and {@code y}, multiple invocations of
21      *     {@code x.equals(y)} consistently return {@code true}
22      *     or consistently return {@code false}, provided no
23      *     information used in {@code equals} comparisons on the
24      *     objects is modified.
25      * <li>For any non-null reference value {@code x},
26      *     {@code x.equals(null)} should return {@code false}.
27      * </ul>
28      * <p>
29      * The {@code equals} method for class {@code Object} implements
30      * the most discriminating possible equivalence relation on objects;
31      * that is, for any non-null reference values {@code x} and
32      * {@code y}, this method returns {@code true} if and only
33      * if {@code x} and {@code y} refer to the same object
34      * ({@code x == y} has the value {@code true}).
35      * <p>
36      * Note that it is generally necessary to override the {@code hashCode}
37      * method whenever this method is overridden, so as to maintain the
38      * general contract for the {@code hashCode} method, which states
39      * that equal objects must have equal hash codes.
40      *
41      * @param   obj   the reference object with which to compare.
42      * @return  {@code true} if this object is the same as the obj
43      *          argument; {@code false} otherwise.
44      * @see     #hashCode()
45      * @see     java.util.HashMap
46      */
47     public boolean equals(Object obj) {
48         return (this == obj);
49     }
View Code

比较的是引用。

equals方法有几个特性:

1.反身性  2.对称性  3.传递性  4.一致性  5.对于非空对象x,x.equals(null)返回false

int hashCode(),Object clone(),toString(),notify(),notifyAll(),wait(long timeout),wait(long timeout, int nanos),wait(),finalize()

转载于:https://www.cnblogs.com/DamonGeng/p/10555657.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值