美文网首页
重写hashcode

重写hashcode

作者: 潘千千 | 来源:发表于2021-11-27 11:04 被阅读0次

    @Override
    public boolean equals(Object o) {
    if(this == o) {
    return true;
    }

        if(!(o instanceof Emp)) {
            return false;
        }
        
        Emp emp = (Emp)o;
        
        return this.id == emp.id;
    }
    
    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + id;
        return result;
    }
    
    public int getId() {
        return id;
    }
    
    public void setId(int id) {
        this.id = id;
    }
    

    ///3
    Iterator it = map.entrySet().iterator();
    while (it.hasNext()) {
    Map.Entry m = (Map.Entry) it.next();
    System.out.println("key:"+m.getKey()+",value:"+m.getValue());
    }
    //4
    public Computer(float price,String year,String time,String people) {
    this.price = price;
    this.year = year;
    super.setRksj(time);
    super.setRkczy(people);

    }

    相关文章

      网友评论

          本文标题:重写hashcode

          本文链接:https://www.haomeiwen.com/subject/ahifxrtx.html