I have a function functionAcceptsMethod
which accepts a runnable method as a parameter, I want to call functionAcceptsMethod
by passing a method with parameters.
when I call functionAcceptsMethod
by passing without parameters its fine but how to pass a function with parameters.
here is an example
private void testFun() {
functionAcceptsMethod(this::funWithoutParams);
functionAcceptsMethod(this::funWithParams); // this where I need to pass params
//functionAcceptsMethod(() -> funWithParams("abcd")); // I tried this, is this the right
//way?
}
private void funWithoutParams() {
//do something
}
private void funWithParams(String testString) {
//do something
}
private void functionAcceptsMethod(Runnable method) {
method.run();
}