??????Java????У???Щ????????????????淶??????API?????????????????У??????????Щ?????????÷???????????μ????÷?????Joshua Bloch???Effective Java??????????????????????????????????????????????÷?????
??????????????д???????????????????????????????????????????????????Σ???????κε?????
??????
????????
????equals()
????hashCode()
????compareTo()
????clone()
????????
????StringBuilder/StringBuffer
????Random.nextInt(int)
????Iterator.remove()
????StringBuilder.reverse()
????Thread/Runnable
????try-finally
????????/?????
???????????????????????
??????????????????????
????????????????
???????????д???
???????????
???????
????????
????????????
????????????
???????飺
??????????
?????????????Χ??????????
?????????????С
?????????
????????????????int
????????4?????
???????equals()
????class Person{
????String name;
????int birthYear;
????byte[]raw;
????public boolean equals(Object obj){
????if(!obj instanceof Person)
????return false;
????Person other=(Person)obj;
????return name.equals(other.name)
????&&birthYear==other.birthYear
????&&Arrays.equals(raw??other.raw);
????}
????public int hashCode(){...}
????}
??????????????Object?????????????Χ??
????foo.equals(null)??????false????????NullPointerException???????null instanceof?????????????false???????????????????С???
?????????????????磬int?????????==??????????????????????Arrays.equals()??
????????equals()???????????????hashCode()????equals()????????
?????ο???java.lang.Object.equals(Object)??
???????hashCode()
????class Person{
????String a;
????Object b;
????byte c;
????int[]d;
????public int hashCode(){
????return a.hashCode()+b.hashCode()+c+Arrays.hashCode(d);
????}
????public boolean equals(Object o){...}
????}
??????x??y???????????x.equals(y)==true???????????x.hashCode()==y.hashCode()??
?????????淴???????x.hashCode()!=y.hashCode()?????x.equals(y)==false?????????