I am following this post on getting distinct elements from ArrayList.
My code:
List<HpbAlertKeeperDTO> distinctAlertKeeperDTOs = alertKeeperDeviceDTO.getBizHpbAlertKeeperDTO().stream()
.filter(distinctByKey(HpbAlertKeeperDTO::getKeeperId)).collect(Collectors.toList());
and my distinctByKey is:
protected static <T> Predicate<T> distinctByKey(Function<? super T, ?> keyExtractor) {
Set<Object> seen = ConcurrentHashMap.newKeySet();
return t -> seen.add(keyExtractor.apply(t));
}
But the error from the IDE is: it is highlighting the parameter of distinctByKey in the first code snippet.
Non-static method cannot be referenced from a static context
My understanding of this error message is: getKeeperId() is not a static method. But in my HpbAlertKeeperDTO is just a normal POJO, with getter and setter methods of a variable.
How do I get around this error? Please feel free to ask me to provide more details.
Thanks and please help.