[英]Java 8 type inference with non-static access of static members
考慮以下代碼:
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
}
}
前幾天,當我意外地以非靜態方式調用靜態方法時,遇到了這一情況。 我知道您不應該以非靜態的方式調用靜態方法,但是我仍然想知道,為什么在這種情況下為什么不能推斷類型呢?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.