public class Main {
public void testMethod(Object o){
System.out.println("Object Method called");
}
public void testMethod(String s){
System.out.println("String Method called");
}
public static void main(String[] args) {
new Main().testMethod(null);
}
}
이 프로그램은 마술처럼 String 메서드를 호출합니까? Java 컴파일러가 String 메소드를 사용하기로 결정한 기준은 무엇입니까? 누군가 제게이 이유를 가르쳐 주시겠습니까?Java는 다른 매개 변수 유형을 가진 동일한 이름의 메소드를 어떻게 결정합니까?
Object 메서드를 사용하려면 매개 변수를 Object로 캐스팅 할 수 있습니다. - 새 Main(). testMethod ((객체) null); –