Two parameters in the Lambda expression
-
How do you put the lymbda expression on two different parameters? For example
Function<Integer, String> getConcatenatedString = (amount, s) -> {...}
amount - Integer, s - String.
Is there any other possibility, other than defining an interface like:
@FunctionalInterface interface Function3<A, B, R> { public R apply (A a, B b); }
-
You probably need the following design:
BiFunction<Integer, String, String> getConcatenatedString = (Integer amount, String s) -> { return Integer.toString(amount) + " " + s; };
By the way, since the lymbda expression is the only one, it can be shorter:
BiFunction<Integer, String, String> getConcatenatedString = (Integer amount, String s) -> Integer.toString(amount) + " " + s;