I'm trying to use method references to capture method invocations and am hitting some limitations. This works fine:
<T> void capture(Function<T, ?> in) {
}
private interface Foo {
String getBar();
}
capture(Foo::getBar);
But if I change the signature of Foo.setBar to something like this:
private interface Foo {
void setBar(String bar);
}
capture(Foo::setBar);
I get an error:
Cannot make a static reference to the non-static method setBar(String) from the type MyTest.Foo
It's not clear to me what the restriction is. Ideally I'd like to use method references to capture invocations on standard setter. Is there any way to do this?
static
modifier?Foo
and calls a method on that reference.