Is there a predefined Function in Java 8 that does something like this:
static Function constant(R val) {
return (T t) -> {
A simple lambda, x -> val
seems to be equivalent to your method;
Function<Integer, Integer> test1 = constant(5);
Function<Integer, Integer> test2 = x -> 5;
...both ignore the input and output the constant 5 when applied;
> System.out.println(test1.apply(2));
5
> System.out.println(test2.apply(2));
5