使用范型类的方法引用时会出现上下文获取不到范型
在方法前指定对应的范型即可
List<Pair<String, Long>> data = new ArrayList<>();
// Non-static method cannot be referenced from a static context
data.stream()
.sorted(Comparator.comparing(Pair::getValue).reversed())
.collect(Collectors.toList());
// 指定对应的范型
data.stream()
.sorted(Comparator.<Pair<String, Long>, Long>comparing(Pair::getValue).reversed())
.collect(Collectors.toList());