Map.Entry <! - ?,? - >作为对象返回[Bukkit插件加载器,AddonDescriptionFile]

时间:2015-03-12 12:17:49

标签: java bukkit

在代码中:

for (Map.Entry<?,?> command : ((Map)map.get("commands")).entrySet()) {
    ImmutableMap.Builder<String, Object> commandBuilder = ImmutableMap.builder();
    if (command.getValue() != null) {
        for (Map.Entry<?, ?> commandEntry : ((Map)command.getValue()).entrySet()) {
            if ((commandEntry.getValue() instanceof Iterable)) {
                ImmutableList.Builder<Object> commandSubList = ImmutableList.builder();
                for (Object commandSubListItem : (Iterable)commandEntry.getValue()) {
                    if (commandSubListItem != null) {
                        commandSubList.add(commandSubListItem);
                    }
                }
                commandBuilder.put(commandEntry.getKey().toString(), commandSubList.build());
            }
            else if (commandEntry.getValue() != null) {
                commandBuilder.put(commandEntry.getKey().toString(), commandEntry.getValue());
            }
        }
    }
    commandsBuilder.put(command.getKey().toString(), commandBuilder.build());
}

第二个Map.Entry以Object身份返回,但第一个工作正常吗?

任何帮助?

ERROR: Required: Map.Entry<?, ?>
       Found: Object

屏幕截图:

enter image description here

1 个答案:

答案 0 :(得分:0)

似乎没有指定任何类型参数,Map.entrySet()只返回一个普通的未参数化Set。要获得Set<Map.Entry<?,?>>,您必须至少使用通配符类型参数,即强制转换为Map<?,?>

for (Map.Entry<?, ?> commandEntry : ((Map<?,?>) command.getValue()).entrySet()) {