I am trying to use method references to call capture labels and push some restrictions. This works great:
<T> void capture(Function<T, ?> in) { } private interface Foo { String getBar(); } capture(Foo::getBar);
But if I changed the signature of Foo.setBar to something like this:
private interface Foo { void setBar(String bar); } capture(Foo::setBar);
I get an error message:
Cannot make a static reference to the non-static method setBar(String) from the type MyTest.Foo
I donβt understand what such a restriction is. Ideally, I would like to use method references to capture references to a standard setter. Is there any way to do this?
java java-8 method-reference
Josh stone
source share