升序到降序的类型变化

//升序
total.sort(Comparator.comparingInt(o -> MapUtils.getInteger(o, "total", 0)));
//降序
total.sort(Comparator.comparingInt(o -> MapUtils.getInteger(o, "total", 0)).reversed());

想要把升序改为降序后,报这个错误:
‘getInteger(java.util.Map<? super K,?>, K, java.lang.Integer)’ in ‘org.apache.commons.collections4.MapUtils’ cannot be applied to ‘(java.lang.Object, java.lang.String, int)’

错误信息表明 MapUtils.getInteger 方法的参数类型不匹配。问题在于 MapUtils.getInteger 方法需要一个具有通配符类型的 Map 对象,而不是 java.lang.Object。

这里的 MapUtils.getInteger 方法参数类型需要 Map<String, ?>,所以我们在调用时进行了类型转换 (Map<String, ?>)。这样可以确保类型匹配并避免编译错误。运行这段代码后,列表中的元素将按 “total” 键的值从大到小排序。

相关推荐

  1. 升序类型变化

    2024-07-11 11:52:01       21 阅读
  2. postgresql 大于当前时间升,小于当前时间

    2024-07-11 11:52:01       20 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-07-11 11:52:01       66 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-07-11 11:52:01       70 阅读
  3. 在Django里面运行非项目文件

    2024-07-11 11:52:01       57 阅读
  4. Python语言-面向对象

    2024-07-11 11:52:01       68 阅读

热门阅读

  1. 编程入门题:画矩形(C语言版)

    2024-07-11 11:52:01       21 阅读
  2. k8s 部署RuoYi-Vue-Plus之nginx部署

    2024-07-11 11:52:01       23 阅读
  3. js 日期比较大小

    2024-07-11 11:52:01       18 阅读
  4. 定个小目标之刷LeetCode热题(43)

    2024-07-11 11:52:01       19 阅读
  5. SLAM中的块矩阵与schur补

    2024-07-11 11:52:01       23 阅读
  6. 第2章 大话 ASP.NET Core 入门

    2024-07-11 11:52:01       23 阅读
  7. git github gitee 三者关系

    2024-07-11 11:52:01       21 阅读