Consider the following two functional interfaces ( java.lang.Runnable and java.util.concurrent.Callable<V>
):
public interface Runnable {
void run();
}
public interface Callable<V> {
V call();
}
Suppose that you have overloaded
the method invoke as follows:
void invoke(Runnable r) {
r.run();
}
<T> T invoke(Callable<T> c) {
return c.call();
}
Consider below method invokation
String s = invoke(() -> "done");
This will call invoke(Callable)
. but How? How compliler is able to determine the Type as callable? I didn't understand from Oracle doc i have read.