Search code examples
functionlambdajava-8

Java8 Lambda function - adding new parameter


I have following code :

categoryList = Prices.stream()
               .filter(price -> price.getPrice() != null)
               .map(this::createCategory)
               .filter(Objects::nonNull)
               .collect(Collectors.toList());

And the method looks like :

private Category createCategory(PriceCategory price) {
        Category category = new Category();
        category.setId(price.getId());
        return category;
    }

I want to add a new parameter to the method createCategory - like createCategory(PriceCategory price, response) But I don't have idea about setting this new parameter in the lambda function. Can anyone please help in this


Solution

  • can't you simply create a lambda instead?

    .map(x -> createCategory(x, response))