So I ran across this situation today while writing some unit tests. Its somewhat an esoteric question, but I don't understand why this code functions this way. Here's the code:
public class Test {
public static void main(String[] args) {
doSomething(null);
}
public static void doSomething(Class<?> c) {
System.out.println("Parameterized with Class<?>");
}
public static void doSomething(Object o) {
System.out.println("Parameterized with Obejct");
}
}
In the above example, the call to doSomething will resolve to the method parameterized with Class, but null doesn't contain any of the methods within Class. Why does this happen? The behavior is the same if parameterized with the raw type.