Function Java8 Lamda函数-添加新参数
我有以下代码:Function Java8 Lamda函数-添加新参数,function,lambda,java-8,Function,Lambda,Java 8,我有以下代码: categoryList = Prices.stream() .filter(price -> price.getPrice() != null) .map(this::createCategory) .filter(Objects::nonNull) .collect(Collectors.toList()); 方法如下所示: private Cate
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吗
.map(x -> createCategory(x, response))
你不能简单地创建一个lambda吗
.map(x -> createCategory(x, response))
您正在使用方法引用。只需将其更改为lambda表达式,问题就会消失(提示:lambda表达式就是您在前面的
过滤器
步骤中使用的表达式)。可能,但您需要首先定义响应
s值的来源。您使用的是方法引用。只要将其更改为lambda表达式,问题就会消失(提示:lambda表达式就是您在前面的filter
步骤中使用的表达式)。可能,但您需要首先定义response
s值的来源。仅在关闭中定义了response
值的情况下。仅在关闭中定义了response
值的情况下。