如果 hashcode return 是一个常量值并且等于 return false,那么 get 方法如何在 hashmap 中工作?

How does get method works in hashmap if hashcode returns a contant value and equals return false?

我有 Dept class 如下,我已经覆盖了 hashcode 和 equals 方法。哈希码 return 是一个常量值,始终等于 return false。

public class Dept {
    
        private int depid;
        private String deptname;
    
        public Dept(int depid, String deptname) {
            super();
            this.depid = depid;
            this.deptname = deptname;
        }
    
        public int getDepid() {
            return depid;
        }
    
        public void setDepid(int depid) {
            this.depid = depid;
        }
    
        public String getDeptname() {
            return deptname;
        }
    
        public void setDeptname(String deptname) {
            this.deptname = deptname;
        }
    
        @Override
        public int hashCode() {
    
            return 100;
        }
    
        @Override
        public boolean equals(Object obj) {
    
            return false;
        }
    
        @Override
        public String toString() {
            return "Dept [depid=" + depid + ", deptname=" + deptname + "]";
        }
    }

我有一个主要方法

public static void main(String[] args) {
        Dept dept = new Dept(1, "it");
        Dept dept1 = new Dept(1, "it");
        Dept dept2 = new Dept(1, "it");

        HashMap<Dept, String> map = new HashMap<>();
        map.put(dept, "a");
        map.put(dept1, "b");
        map.put(dept2, "c");

        System.out.println(map.get(dept2));// returns c
        System.out.println(map.get(dept1));// returns b
}

根据我读过的理论,hashcode returning 一个常量值会给我们 hashmap 中相同的 bucket 索引,因此值存储在单个 bucket 中 对于 equals 方法,它是 returning false,因此逻辑上相同的 dept 对象被多次保存。 get 方法如何 return 从 hashmap 中获取完全正确的值?

an object is always supposed to be equals to itself, HashMap first checks using == (object identity) 以来,因为这要快得多并且在许多常见用例中都匹配。