import java.util.concurrent.Callable;
public class AdvancedLambda {
static void invoke(Runnable r){
r.run();
}
static Object invoke(Callable c) throws Exception {
return c.call();
}
public static void main(String[] args) throws Exception {
String s = (String) invoke(() -> true);
System.out.println(s);
}
}
有人能帮我理解一下吗?我之前认为我们只能在Java 8中实现接口并覆盖其方法(用Lambda表达式替换匿名类)时使用Lambda表达式。
此外,在什么情况下会调用 invoke(Runnable r)
方法?