I have two overload method and a test method
<T, R> R ifNotEmpty(T o, Function<T, R> function)
<T> void ifNotEmpty(T o, Consumer<T> consumer)
void test(String) {
//do nothing
}
when I call
ifNotEmpty("aaa", x -> test(x));
I get an error
Ambiguous method call. Both
ifNotEmpty(String,Function<String, R>) and
ifNotEmpty(String,Consumer<String>) match
Why?
And when I write like this,it's correct
ifNotEmpty("aaa", this::test);
like this also correct
ifNotEmpty("aaa", (String x) -> test(x));
Why?
I used JDK-1.8 and IDEA-2017.3.5-community edition