Zahari February 2016

Not able to resolve the type of a lambda parameter

So I am trying to implement a custom collector but unfortunatelly I am stuck at a pretty interesting problem:

@Override
public BiConsumer<Map<LocalDate, List<TripResultDTO>>, TripResultDTO> accumulator() {
    return (acc,elem) -> {
        long departureTime = elem.getOutbound().getDepartureTimeLocal();
        LocalDate departureDate = new LocalDateTime(departureTime).toLocalDate();
        List<TripResultDTO> othersInTheSameDay = acc.getOrDefault(departureDate,new LinkedList<>());
        othersInTheSameDay.add(elem);
        acc.put(departureDate,othersInTheSameDay);
    };
}

So in the code above, the compiler cannot resolve any of the methods of the elem object which is of type TripResultDTO.

Needless to say the getOutbound method is highlighted in red and cannot be resolved. Its quite strange by looking at the intelli sense that the TripResultsDTO seems to treated simply as an instance of Object rather than TripResultDTO. Do you have any idea why that might be happening.

Also any idea for doing what I am doing in a better way are welcome.

Answers


Zahari February 2016

So actually that was a pretty noob mistake. What I had done in the signature of the collector was:

public class CheapestPerDayCollector <TripResultDTO> implements Collector<TripResultDTO, Map<LocalDate, List<TripResultDTO>>, List<TripResultDTO>> {

which actually signified the TripResultsDTO as a generic type rather than the actual class. I rewrote it as :

public class CheapestPerDayCollector  implements Collector<TripResultDTO, Map<LocalDate, List<TripResultDTO>>, List<TripResultDTO>> {

and now everything works fine.

Post Status

Asked in February 2016
Viewed 2,554 times
Voted 12
Answered 1 times

Search




Leave an answer