我已经浏览了这个链接;但我对以下示例代码感到困惑:-
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!
}
}
我得到的错误是:-
ankit@stream:/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!
任何建议,请