IntelliJ Java 8

This line compiles

List<Trade> trades = otrades.stream()
                     .sorted(Comparator.comparing(t -> t.getMeta().getTradeDate()))
                     .collect(Collectors.toList()));

But adding 'thenComparing' is not

List<Trade>trades = otrades.stream()
                   .sorted(Comparator.comparing(t -> t.getMeta().getTradeDate())
                   .thenComparing(t -> t.getName()))
                   .collect(Collectors.toList()));

The compiler error is that it cannot solve getMeta ().

(Since there are no errors in the code, I assume that the problem is in IntelliJ).

thank

+4
source share
1 answer

For some reason, I don’t understand, in the second case, the output input error is not executed. But you can specify the typet

List<Trade>trades = otrades.stream()//*******
   .sorted(Comparator.comparing(     (Trade t) -> t.getMeta().getTradeDate())
   .thenComparing(t -> t.getName()))
   .collect(Collectors.toList()));

In your example, the compiler found that t- this is something else that a Trade(possibly Object). Therefore, the method getMeta()cannot be found.

+4
source

Source: https://habr.com/ru/post/1538612/


All Articles