public class Test
{
public void myMethod(Object o)
{
System.out.println("My Object");
}
public void myMethod(String s)
{
System.out.println("My String");
} public static void main(String args[])
{
Test t = new Test();
t.myMethod(null);
}}
null is passed as an argument to the method myMethod(String s) will be called. Had myMethod(String s) not present , myMethod(Object o) would be called.
究竟调用函数匹配的顺序是什么有官方的解释吗?
t.myMethod((Object)null);
这样子来强调null的"类型".