简体   繁体   English

TreeMap#containsKey放置后立即返回false

[英]TreeMap#containsKey return false just after put

I know this question has been treated before but I've read questions and tried to fix my own with no result, I think I'm missing something with the TreeMap or Map implementation... 我知道这个问题之前已经得到解决,但是我已经阅读了问题,并试图解决我自己的问题,但没有结果,我想我在TreeMap或Map实现中缺少了一些东西...

if(arme != null){
    if(!hommesArmes.containsKey(arme)){
        System.out.println(hommesArmes.containsKey(arme));
        hommesArmes.put(arme, new TreeSet<Homme>());
        System.out.println(hommesArmes.containsKey(arme));
    }
    hommesArmes.get(arme).add(homme);
}

Why do I get false twice when I run this? 为什么运行此命令时我会两次出错? I've tried with Integer instead of Arme and it worked, I don't understand what I'm doing wrong. 我尝试使用Integer而不是Arme并成功,但我不明白自己在做什么错。

我传递给TreeMap的构造函数的Comparator对象有问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM