【发布时间】:2015-06-07 15:03:04
【问题描述】:
考虑以下类:
public void method() {
test(() -> { });
}
void test(Runnable a) {
System.out.println("Test 1");
}
void test(A a) {
System.out.println("Test 2");
}
interface A extends Runnable {
}
调用方法method() 将导致Test 2 输出。这意味着,lambda 表达式 () -> { } 被隐式转换为 A。为什么?
【问题讨论】:
标签: java lambda type-conversion java-8 overloading