I am using lamdbas so I can consistently set the properties of a ModelObject according to the values I can retrieve from three different objects. The code works like this:
public class Processor {
private void bar(Setter setter, MyClass myObject) {
String variable = myObject.getStringByABunchOfMethods();
setter.setVariable(variable);
}
protected void foo(...) {
...
bar(value -> model.setA(CONSTANT, value), aObject);
bar(value -> model.setB(value), bObject);
bar(value -> model.setC(value), cObject);
...
}
private interface Setter {
public void setVariable(String string);
}
}
public interface IModel {
public void setA(String arg0, String arg1);
public void setB(String arg0);
public void setC(String arg0);
}
I have read here that it is possible to rewrite bar(value -> model.setB(value), bObject);
to bar(model::setB, bObject)
. I think this looks better and more concise, but I haven't found a way to rewrite the setA
method to a double :: notation. Can anyone tell me if this is possible, and if so: how is this possible?