0

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

2
  • You are using a method reference. Just change it to a lambda expression and the problem disappears (hint: a lambda expression is what you are using in the preceding filter step). Commented Nov 7, 2017 at 9:51
  • Possible but you need to define first where responses values will come from. Commented Nov 7, 2017 at 10:45

1 Answer 1

3

can't you simply create a lambda instead?

.map(x -> createCategory(x, response)) 
Sign up to request clarification or add additional context in comments.

1 Comment

Only in the case response value is defined in the closure.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.