setter的Lambda表达式 [英] Lambda expression for setter

查看:261
本文介绍了setter的Lambda表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们可以为getter使用lambda表达式,如下所示

We can lambda expression for getter as below

Function<Student, String> studentNameGetter = Student::getName;

如何为setter创建lambda表达式?

How about creating lambda expression for the setter?

推荐答案

我不确定你为setter创建一个lambda表达式是什么意思。

I'm not sure what you mean by creating a lambda expression for the setter.

您尝试做的是将方法引用分配给合适的功能接口。在这种情况下,最佳匹配是 BiConsumer

What it looks like you are trying to do is to assign the method reference to a suitable Functional Interface. In that case, the best match is to a BiConsumer:

BiConsumer<Student, String> studentNameSetter = Student::setName;

这篇关于setter的Lambda表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆