【发布时间】:2017-11-07 09:46:58
【问题描述】:
我有以下代码:
categoryList = Prices.stream()
.filter(price -> price.getPrice() != null)
.map(this::createCategory)
.filter(Objects::nonNull)
.collect(Collectors.toList());
方法如下:
private Category createCategory(PriceCategory price) {
Category category = new Category();
category.setId(price.getId());
return category;
}
我想为方法 createCategory 添加一个新参数 - 例如createCategory(PriceCategory price, response) 但我不知道如何将这个新参数设置为 lamda 函数。有人可以帮忙吗
【问题讨论】:
-
您正在使用方法参考。只需将其更改为 lambda 表达式,问题就会消失(提示:您在前面的
filter步骤中使用的是 lambda 表达式)。 -
可能,但您需要先定义
responses 值的来源。