[Solved] Java 8 comparator not working


The comparator seems correct. The problem seems to be in your filter clause, where you compare the event id to the device id

lastDeviceEvent = deviceEvents
                .stream()
                .filter (o -> o.getDeviceId().equals(deviceId)) // Original code used getId()
                .sorted(comparing((DeviceEvent de) -> de.getId()).reversed())
                .findFirst()
                .get();

solved Java 8 comparator not working