sqr*_*pin 8 java type-inference java-8 method-reference
请考虑以下代码:
class Test {
void accept(Consumer<Integer> c) {}
static void consumer(Integer i) {}
void foo() {
accept(this::consumer); // The method accept(Consumer<Integer>) in the type Test is not applicable for the arguments (this::consumer)
accept(Test::consumer); // Valid
}
}
Run Code Online (Sandbox Code Playgroud)
前几天我偶然以非静态方式调用静态方法时遇到了这个问题.我知道你不应该以非静态的方式调用静态方法,但我仍然想知道,为什么不能在这种情况下推断出类型呢?
| 归档时间: |
|
| 查看次数: |
272 次 |
| 最近记录: |