次のコードを検討してください。
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
}
}
先日、静的メソッドを非静的な方法で誤って呼び出したときに、これに遭遇しました。非静的な方法で静的メソッドを呼び出すべきではないことはわかっていますが、この場合、型を推測できないのはなぜでしょうか?