警告:[重载] 方法 m1 可能与方法 m2 不明确
import java.util.function.*;
class Test {
void test(int foo, Consumer<Integer> bar) { }
void test(long foo, Consumer<Long> bar) { }
void test(float foo, Consumer<Float> bar) { }
void test(double foo, Consumer<Double> bar) { }
}
当我编译这个时,我得到一些警告:javac -Xlint Test.java
Test.java:4: warning: [overloads] test(int,Consumer<Integer>) in Test is potentially ambiguous with test(long,Consumer<Long>) in Test
void test(int foo, Consumer<Integer> bar) { }
^
Test.java:6: warning: [overloads] test(float,Consumer<Float>) in Test is potentially ambiguous with test(double,Consumer<Double>) in Test
void test(float foo, Consumer<Float> bar) { }
^
2 warnings
如果我更改为警告,则消失。此程序是无警告的:Consumer
Supplier
import java.util.function.*;
class Test {
void test(int foo, Supplier<Integer> bar) { }
void test(long foo, Supplier<Long> bar) { }
void test(float foo, Supplier<Float> bar) { }
void test(double foo, Supplier<Double> bar) { }
}
为什么?此警告是什么意思?这些方法如何模棱两可?禁止显示警告是否安全?