The cause of this is, that there are multiple fitting methods (constructor in this case) that do fit the call. If there is more then one fitting method for a method call it allways takes the most specific one. In this case, String is more specific then Object.
This can be seen in the inheritance chain. String inherits from Object
If there are two equally specific methods, then your compiler will tell you so with the error message The method method(parameter) is ambiguous for the type Class. This can be seen in this example.
public class A {
public static void main(String[] args) {
// compiler complains with:
// The method test(Object) is ambiguous for the type A
test(null);
}
static void test(Object o) {
System.out.println("IN OBJECT");
}
static void test(A a) {
System.out.println("IN A");
}
static void test(B b) {
System.out.println("IN B");
}
class B {
}
}
With a slight change, by letting B inherit from A the method test(B) is getting more specific, because B is more specific then A, and the compiler error message is gone.
public class A {
public static void main(String[] args) {
test(null);
}
static void test(Object o) {
System.out.println("IN OBJECT");
}
static void test(A a) {
System.out.println("IN A");
}
static void test(B b) {
System.out.println("IN B");
}
class B extends A{
}
}
new ConTest((Object)null);