M
mingclee1
Hello,
I have a question when passing null in the parameter when invoking a
method. Consider:
public class Test1
public void method3(Object o){
System.out.println("Object");
}
public void method3(String s){
System.out.println("string s");
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Test1 test = new Test1();
test.method3(null);
}
}
In JDK 1.5 or 5.0(latest one from sun), it will call method3(String s).
And if I comment out method3(String s), then it will call
method3(Object o). However in JDK1.4.2, I get compilation error:
the method method3(Object) is ambiguous for the type Test1
So, my question is why is it in JDK1.5, when calling
test.method3(null), it knows to invoke method3(String) over
method3(Object)? And also what is really happening when someone invoke
a method with null parameter without specifying a type? (Like
method3(null)
Thanks in advance for any help!
I have a question when passing null in the parameter when invoking a
method. Consider:
public class Test1
public void method3(Object o){
System.out.println("Object");
}
public void method3(String s){
System.out.println("string s");
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Test1 test = new Test1();
test.method3(null);
}
}
In JDK 1.5 or 5.0(latest one from sun), it will call method3(String s).
And if I comment out method3(String s), then it will call
method3(Object o). However in JDK1.4.2, I get compilation error:
the method method3(Object) is ambiguous for the type Test1
So, my question is why is it in JDK1.5, when calling
test.method3(null), it knows to invoke method3(String) over
method3(Object)? And also what is really happening when someone invoke
a method with null parameter without specifying a type? (Like
method3(null)
Thanks in advance for any help!