Yours Function<Foo, String> func2 = Foo::setBar;
is a compilation error, because public void setBar(String bar)
it is not a function from Foo
to String
, it is actually a function from String
to Void
.
If you want to send the installer as a reference to a method, you need BiConsumer, taking Foo
and String
how
final BiConsumer<Foo, String> setter = Foo::setBar;
, Foo
, Consumer
,
Foo foo = new Foo();
final Consumer<String> setBar = foo::setBar;