Boolean外覆类中的hashCode()方法有什么用??哈西表是什么东东?感谢,,感谢你的程序代码。。

解决方案 »

  1.   

    hashcode就是对象在内存中的地址,它用来判断对象是否相等
    一般情况下用于基于MAP的容器的KEY值判断,所以自己写的类中要用于MAP容器中的话
    必须覆写hashCode()和 equlas()函数!
      

  2.   

    感谢楼上二位。。我想问的是。。Boolean外覆类中的hashCode()方法有什么用
    在Boolean中有什么作用,我刚学JAVA,不好意思,问的问题比较菜,呵呵
      

  3.   

    一般很少用
    一般重写以后才会用,和EQUALS一起重写
      

  4.   

    例子
    import java.util.*;
    class Dog
    {
      int i = 0;
      Dog(int i)
      {
        this.i=i;
      }
      public int hashCode()
      {
      return i;
      }
      public boolean equals(Object o)
      {
       return (o instanceof Dog)&&(i==((Dog)o).i);
      }
    }
    public class Test6
    {   
      public static void main(String[] args)
      {
       HashMap m = new HashMap(); 
       for(int j =0;j<10;j++)
        m.put(new Dog(j),new Integer(j));
        System.out.println(m.get(new Dog(5)));
      }
    }