equals不是比较对象的内容的么?? 
________________________________此言差矣。Object.equals要返回true,必须参与比较的两个对象引用的是同一个对象,此时 a=b也返回true。
而Integer.equals要返回true,需要参与比较的两个对象都是Integer,并且具有相同的int值,此时 a=b返回false(仅当a、b引用相同对象时返回true)。有此差别的原因在于,Integer重载了Object.equals()方法,其实现是与Object.equals()不同的。请看JavaDoc的解释:Object.equals()The equals method for class Object implements the most discriminating possible equivalence relation on objects; that is, for any 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). Integer.equals()Compares this object to the specified object. The result is true if and only if the argument is not null and is an Integer object that contains the same int value as this object. 而你所定义的class Wa并没有重载equals()方法,仍然是继承自Object的,所以就有了你的实验结果。

解决方案 »

  1.   

    equals不是比较对象的内容的么?? ------------------------------------equals可以是任何你想要的方法。
      

  2.   

    Object的equals方法:如下 ,比较的是地址
     public boolean equals(Object obj) {
    return (this == obj);
        }
    Integer 的equals方法 :如下:比较的是value
     public boolean equals(Object obj) {
    if (obj instanceof Integer) {
        return value == ((Integer)obj).intValue();
    }
    return false;
      }
      

  3.   

    如果要按照你的逻辑来比较,你必需将equals方法重写
    class Wa{
    int i;
    public boolean equals(Wa obj) {     if(*****)
            return true;
         else
            return false;

    }
      

  4.   

    最后一次比较的是地址内容虽然一样,但是类中的i的地址是不同的所以返回false