String中equals忽略的一个问题

问题:
    public void test() {
        Map<String,Object> map = new HashMap<String,Object>();

        map.put("1",0);

        System.out.println("1".equals(map.get("1")));
    }

这边显示的结果为false

原因:
    public boolean equals(Object anObject) {
        if (this == anObject) {
            return true;
        }
        if (anObject instanceof String) {
            String anotherString = (String) anObject;
            int n = value.length;
            if (n == anotherString.value.length) {
                char v1[] = value;
                char v2[] = anotherString.value;
                int i = 0;
                while (n-- != 0) {
                    if (v1[i] != v2[i])
                            return false;
                    i++;
                }
                return true;
            }
        }
        return false;
    }

String中的equals方法,首先判断对象类型,不是String的直接返回false

点赞