You partially applied add . This is due to currying.
In some languages ββthat support a partial application, functions have a default value. you can write code, for example:
increment = add(1) println(increment(2))
The curried function allows you to partially apply this function directly. Java does not support such things without additional mechanisms.
EDIT:
In Java 8 with lambdas and java.util.function you can define a curry function.
import java.util.function.Function; public class Example { public static <T, U, R> Function<T, Function<U, R>> curry(BiFunction<T, U, R> f) { return t -> u -> f.apply(t, u); } public static int add(int x, int y) { return x + y; } public static void main(String[] args) { Function<Integer, Function<Integer, Integer>> curriedAdd = curry(Example::add);
EDIT No. 2: I was wrong! I corrected / changed my answer. As sepp2k pointed out, this is only a partial function application. These two concepts are related and often confused. My defense has a section on the Wikipedia page about mixing.
source share