重複の可能性:
パラメーターの実際のタイプに基づくオーバーロードされたメソッドの選択
パラメーターがリテラルのnull値である場合、オーバーロードされたメソッドはどのように選択されますか?
以下のコードを実行すると、次の出力が得られます。
文字列引数が呼び出されたメソッド...」
なんで?
public class StringObjectPOC {
public static void test(Object o) {
System.out.println("Method with Object argument Called ...");
}
public static void test(String str){
System.out.println("Method with String argument Called ...");
}
public static void main(String[] args) {
StringObjectPOC.test(null);
}
}