Java 8 has Supplier<T>
for 0 parameter functions, Function<T, R>
for 1 parameter functions, and BiFunction<T, U, R>
for 2 parameter functions.
What type represents a function or lambda expression that takes 3 parameters like in
SomeType lambda = (int x, double y, String z) -> x; // what is SomeType?
In C#, Func<T, TResult>
is overloaded for up to 16 parameters so we could write
Func<int, double, string, int> lambda = (int x, double y, string z) => x;
Does the Java standard libraries provide anything similar or do you have to write your own "TriFunction" interface to handle functions with 3 arguments?
You have to write your own functional interface. The JDK does not provide such an implementation.
Note that you can always compose something like a TriFunction
with existing types
Function<Integer, Function<Double, Function<String, Integer>>> func =
i -> d -> s -> i + d.intValue() + Integer.parseInt(s);//whatever random implementation
func.apply(42).apply(1.5).apply("1234");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With