请教如下定义的方法为什么第三行用getIntValue就会编译报错“java: 不兼容的类型: java.lang.Object无法转换为java.util.List<java.util.Map>”
public List<Map> getNewTree(List<Map> oldTree, Map params) {
List<Map> orgTreeList = new ArrayList<>();
List<Map> tempList = oldTree.stream().filter(item -> MapUtils.getLong(item, "tree_level").compareTo(6L) < 0 ).collect(Collectors.toList());
// List<Map> tempList = oldTree.stream().filter(item -> MapUtils.getIntValue(item, "tree_level") <= 5 ).collect(Collectors.toList());
tempList.stream().forEach(item -> {
Map map = new HashMap<>(item);
map.put("tree_type", "3");
orgTreeList.add(map);
});
return orgTreeList;
}
使用getLong编译通过
使用getIntValue编译报错
MapUtils是引入org.apache.commons.collections4包的工具类,其定义如下:
public static <K> int getIntValue(Map<? super K, ?> map, K key) {
Integer integerObject = getInteger(map, key);
return integerObject == null ? 0 : integerObject;
}
public static <K> Long getLong(Map<? super K, ?> map, K key) {
Number answer = getNumber(map, key);
if (answer == null) {
return null;
} else {
return answer instanceof Long ? (Long)answer : answer.longValue();
}
}