We can use a Functional interface as a target type like this:
StringFormatter func = (s1, s2) -> s1 + s2;
in which case you can call it like:
String result = func.format("first","second");
you can also put the logic into a method as such:
static String formatter(StringFormatter func, String s1, String s2){
return func.format(s1, s2);
}
then call it:
String result = formatter((s1, s2) -> s1 + s2, "first", "second");
String anotherResult = formatter((s1, s2) -> s1 +"-"+ s2, "first", "second");
in which case you simply pass the behaviour directly without having to create different inline functions for each scenario.
StringFormatter func = (s1, s2) -> s1 + s2;? then callString result = func.format("first","second");