class Another {
public void method(Object o) {
System.out.println("This is in method which takes object");
}
public void method(String s) {
System.out.println("This is method which takes string");
}
}
public class NewClass {
public static void main(String args[]) {
Another an = new Another();
an.method(null);
}
}
当我尝试执行此操作时,我得到
这是采用字符串的方法
作为输出。为什么不“这是采用对象的方法”?对象也可以为空,字符串也可以为空,为什么不调用第一种方法呢?