Lambda expression for setter

2019-04-04 05:54发布

We have lambda expression for getter as below:

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

How about lambda expression for the setter?

1条回答
We Are One
2楼-- · 2019-04-04 06:40

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

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;
查看更多
登录 后发表回答