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()

posted @ 2019-03-18 22:25  damon11  阅读(144)  评论(0编辑  收藏  举报