如何定义没有args或返回vaule的函数?
Class Foo {
public void setBar(String bar){...};
public String getBar(){...};
}
? getter = Foo::getBar;
? setter = Foo::setBar;
答案 0 :(得分:4)
您遗失的内容是Function
和BiConsumer
// Equivalent to: Function<Foo, String> getter = foo -> foo.getBar();
Function<Foo, String> getter = Foo::getBar
// Equivalent to: BiConsumer<Foo, String> setter = (foo, str) -> foo.setBar(str);
BiConsumer<Foo, String> setter = Foo::setBar