You do not need a special interface: setB is Consumer<String> , and setA is BiConsumer<String, String> . Then you can adapt BiConsumer to Consumer :
Or with the standard method in your interface (if setA always called with a constant, why not?):
interface Model { public void setA(String arg0, String arg1); default void setA(String arg1) {setA(CONSTANT, arg1);} public void setB(String arg0); public void setC(String arg0); }
Or use an adapter from BiConsumer to Consumer :
static <T, U> Consumer<V> adapt(T t, BiConsumer<T, U> biConsumer) { Objects.requireNonNull(biConsumer, "biConsumer"); Objects.requireNonNull(t, "t"); return t -> biConsummer.accept(t, u); }
And using it like this:
protected void foo(...) { ... bar(adapt(CONSTANT, model::setA), aObject); bar(model::setB, bObject); bar(model::setC, cObject); ... }
Note. I used adapt as an example name, but this is a bad name when you mix it with another adapt overload adapt (due to the generic and erasable type). I call it fixLeftValue .
Beware that adapt will be generated every time foo called.
source share