0

I know there are a lot of duplicate questions in here. But I couldn't find a similar scenario to mine. Non-static variable cannot be referenced from a static context this question talk about basic java instances and things. But my problem is with Java8 stream() and its map(). I have this getPredicates() function and it returns a Map of Predicates.

public static Map<String, Predicate> getPredicates() {
    Map<String, Predicate> listOfPredicates = new HashMap<>();
    Predicate<LocalRequestDTO> allFilter = request -> (!StringUtils.isBlank(request.getSuvc())
            && !StringUtils.isBlank(request.getSuffix()) && !StringUtils.isBlank(request.getSite()));
    listOfPredicates.put("allFilter", allFilter);
    return listOfPredicates;
}

In the same class there is a another method called handleFilterBySuvc which calls the getPrediate() function.

public void handleFilterBySuvc(){
 List<String> suvcList = localRequestDTOList.stream().filter(getPredicates().get("suvcFilter")).map(LocalRequestDTO::getSuvc).collect(Collectors.toList());
}

What this function does is create a list of strings. But this gives the above error in the title by highlighting the .map(LocalRequestDTO::getSuvc). But if I remove the getPredicate() call from the .filter() and directly create the same predicate in the handleFilterBySuvc() function and call that inside the .filter() the error is gone. Can anyone find a reason?

0 Answers0