I am unable to figure what would be the return type of these functions fooBar() and barFoo()
in Java and getting the following errors.
import java.util.function.Function;
class FooBar {
private void foo() {
}
private void bar(String s) {
}
public FunctionalInterface fooBar() {
return this::foo;// The type of foo() from the type FooBar is void, this is incompatible with the
// descriptor's return type: Class<? extends Annotation>
}
public Function<String, Void> barfoo() {
return this::bar;// The type of bar(String) from the type FooBar is void, this is incompatible
// with the descriptor's return type: Void
}
}
Is there any way to return these functions, so that they can be used by other functions?
Setting return type to FuncionalInterface isn't helpful.
Setting return type to Void, but however it isn't compatible with void
Thanks!
There are types which match
void f()andvoid f(String a). They areRunnableandConsumer<String>respectively.So your code becomes: