For a reason I don't understand, type inference fails in the second case. But you can give the type of t
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 finds that t
is something else that a Trade
(probably Object
). That's why the method getMeta()
cannot be found.