請參閱該Java類呼叫似乎模棱兩可,但意想不到的輸出完美運行
class Demo
{
public static void a(String s)
{
System.out.println("string called");
}
public static void a(Object a)
{
System.out.println("Object called");
}
public static void main(String...asrgs)
{
a(null);
}
}
這段代碼的輸出是「字符串名爲」但我不能夠理解編譯器是如何能夠與解決對象和字符串。
此外,檢查該代碼段
class Demo
{
public static void a(String s)
{
System.out.println("string called");
}
public static void a(Integer n)
{
System.out.println("number called");
}
public static void a(Object a)
{
System.out.println("Object called");
}
public static void main(String...asrgs)
{
a(null);
}
}
在這裏我們得到了有關曖昧通話編譯時錯誤(這是相當明顯)。 對此有什麼好的解釋?
第一個或第二個解釋?如果可能的話,兩者都是 – 2014-10-03 07:25:03
:) – Gagan93 2014-10-03 07:27:00