I have a question about passing a method reference as an argument in java (util) functions.
I have two functions
Function<Value, Output> f1 = (val) -> {
Output o = new Output();
o.setAAA(val);
return o;
};
Function<Value, Output> f2 = (val) -> {
Output o = new Output();
o.setBBB(val);
return o;
};
I want to combine them into one function, which should look like
BiFunction<MethodRefrence, Value, Output> f3 = (ref, val) -> {
Output o = new Output();
Output."use method based on method reference"(val);
return o;
};
I want to use this function, for example
f3.apply(Output::AAA, number);
Is it possible? I can not understand the correct syntax of how to make such a function.
source
share