List<Country> collect = allCountries.stream()
.sorted(Comparator.comparing(country -> country.getCities().size()))
.collect(Collectors.toList());
我有上面使用流的java代码,它按预期工作。但是,当我尝试颠倒顺序时执行以下操作:
List<Country> collect = allCountries.stream()
.sorted(Comparator.comparing(country -> country.getCities().size()).reversed())
.collect(Collectors.toList());
我得到:
Cannot resolve method 'getCities' in 'Object'
为什么会这样,在这种情况下我将如何反转流?