我曾经使用过此link消失了;但我感到困惑与下面的示例代码: -选择最具体方法 - 整蛊方法重载?
public class NullTest {
public static void method(Object obj){
System.out.println("method with param type - Object");
}
public static void method(String str){
System.out.println("method with param type - String");
}
public static void method(StringBuffer strBuf){
System.out.println("method with param type - StringBuffer");
}
public static void main(String [] args){
method(null); //... compile-time error!
}
}
错误,我得到的是: -
[email protected]:/home/Data/JAVA/practice$ javac trickyMethodOverloading.java
trickyMethodOverloading.java:16: error: reference to method is ambiguous, both method method(String) in trickyMethodOverloading and method method(StringBuffer) in trickyMethodOverloading match
method(null); //... compile-time error!
任何建议,请