无法理解为什么.contains()不会返回true,尝试一切都没有用

时间:2015-03-15 19:18:59

标签: java list bukkit

我可以,找出原因。当List:[NGX-CORE,PingAPI]包含[PingAPI]

时,.contains不会返回true

服务器插件返回:[PingAPI,NGX-CORE] addon.depend返回:[PingAPI]

包含代码:ServerPlugins.contains(addon.depend)

控制台输出:enter image description here

System.out.println("ServerPlugins contents: " + ServerPlugins);
System.out.println("Addon Dependencies: " + addon.depend);
System.out.println("Is addon.depend empty: " + addon.depend.isEmpty());
System.out.println("Does ServerPlugins contain addon.depend: " + ServerPlugins.contains(addon.depend));
System.out.println("Does ServerPlugins contain addon.depend: " + ServerPlugins.contains(addon.depend.toString()));
if (addon.depend.isEmpty()) {
    if (!(m.disabled.contains(addon.name))) {
        Core.Main.m.registerCommands(commands, addon);
        System.out.println("Add-on " + addon.name + " loaded! v" + addon.version);
        addon.onLoad();
        plugins.add(addon);
        m.enabled.add(addon.name);
    } else {
        System.out.println("Add-on " + addon.name + " is disabled and wasn't loaded!");
    }
} else {
    if (ServerPlugins.contains(addon.depend)) {
        if (!(m.disabled.contains(addon.name))) {
            Core.Main.m.registerCommands(commands, addon);
            System.out.println("Add-on " + addon.name + " loaded! v" + addon.version);
            addon.onLoad();
            plugins.add(addon);
            m.enabled.add(addon.name);
        } else {
            System.out.println("Add-on " + addon.name + " is disabled and wasn't loaded!");
        }
    } else {
        System.out.println("Add-on " + addon.name + " requires other plugins to function, required plugins: " + addon.depend.toString().replace("]", "").replace("[", ""));
    }
}

1 个答案:

答案 0 :(得分:1)

我需要做的就是:将.contains替换为.containsAll

.contains查找对象,但不比较对象。然而,.containsAll看起来像是一个集合。

解决了Bram