Object

Object類有如下幾個方法java

equals()ide

 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

比較的是引用。flex

equals方法有幾個特性:ui

1.反身性  2.對稱性  3.傳遞性  4.一致性  5.對於非空對象x,x.equals(null)返回falsethis

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

相關文章
相關標籤/搜索