Lambda expression for setter

风流意气都作罢 提交于 2019-12-21 07:01:03

问题


We have lambda expression for getter as below:

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

How about lambda expression for the setter?


回答1:


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;


来源:https://stackoverflow.com/questions/27759948/lambda-expression-for-setter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!