小编Uma*_*hid的帖子

函数接口作为函数引用

public static void main(String o[]) {
    Map<String, Integer> map = new HashMap<String, Integer>();
    map.put("a", 1);
    map.entrySet().stream().sorted(Comparator.comparing(Entry::getValue)).forEach(System.out::println);
}
Run Code Online (Sandbox Code Playgroud)

上面的代码构建和运行完美但不应该.Comparator.comparing采用函数引用,只有那些接受一个参数并返回一个参数的方法才能映射到此.但是在上面的代码中,getValue被映射并且工作正常但它不带任何参数.代码应该给出构建问题,但不是.我的概念有什么问题吗?

java function java-8 method-reference

5
推荐指数
1
解决办法
110
查看次数

标签 统计

function ×1

java ×1

java-8 ×1

method-reference ×1