我无法理解如何在 Java7 中“迁移”一个简单的比较器。
我在 Java8 中使用的实际版本如下:
private static final Comparator<Entry> ENTRY_COMPARATOR = Comparator.comparing(new Function<Entry, EntryType>() {
@Override
public EntryType apply(Entry t) {
return t.type;
}
})
.thenComparing(Comparator.comparingLong(new ToLongFunction<Entry>() {
@Override
public long applyAsLong(Entry value) {
return value.count;
}
}).reversed());
但在构建阶段我得到这个错误:
static interface method invocations are not supported in -source 7
如何将相同的比较器迁移到 Java7?我正在谷歌搜索并寻找解决方案,但我唯一能想到的是将我自己的类实现为 Comparator 接口实现。
但是如果我走那条路,我如何在同一个“比较”方法中同时应用“比较”、“然后比较”和“反向”?
提前致谢