You can't have a test variable of an anonymous function that implement both Function<Integer, Integer> and Function<String, String> (which is by the way the same interface).
You can however have a nested class with an overloaded apply method, and eventually construct it with lambda functions. This nested class doesn't need to (and can't) implements both Function<Integer, Integer> and Function<String, String>. But as shown in the following example, you actually don't need to implements these interfaces:
static class FunctionOverload {
private final Function<String, String> stringFunction;
private final Function<Integer, Integer> integerFunction;
FunctionOverload(Function<String, String> stringFunction, Function<Integer, Integer> integerFunction) {
this.stringFunction = stringFunction;
this.integerFunction = integerFunction;
}
public String apply(String string) {
return this.stringFunction.apply(string);
}
public Integer apply(Integer integer) {
return this.integerFunction.apply(integer);
}
}
public static void main(String[] args) {
FunctionOverload test = new FunctionOverload(x -> x + x, x -> x + x);
test.apply("5");
test.apply(5);
Stream.of("5").map(test::apply);
Stream.of(5).map(test::apply);
}