The reason is that null
can be considered any type. However, Float[]
and Double
aren't directly related. Float[]
isn't a subtype of Double
, and Double
isn't a subtype of Float[]
. The compiler sees two applicable methods, yet neither method is more specific than the other. In this case, the compiler generates an error because the method call is ambiguous; it doesn't know which method needs to be invoked.
Section 4.1 of the JLS states:
The null reference can always be assigned or cast to any reference type (§5.2, §5.3, §5.5).
In practice, the programmer can ignore the null type and just pretend that null is merely a special literal that can be of any reference type.
In addition, Section 15.12.2.5 of the JLS, about choosing the most specific method, states:
It is possible that no method is the most specific, because there are two or more methods that are maximally specific. In this case:
If all the maximally specific methods have override-equivalent signatures (§8.4.2), then:
If exactly one of the maximally specific methods is concrete (that is, non-abstract or default), it is the most specific method.
Otherwise, if all the maximally specific methods are abstract or default, and the signatures of all of the maximally specific methods have the same erasure (§4.6), then the most specific method is chosen arbitrarily among the subset of the maximally specific methods that have the most specific return type.
In this case, the most specific method is considered to be abstract. Also, the most specific method is considered to throw a checked exception if and only if that exception or its erasure is declared in the throws clauses of each of the maximally specific methods.
Otherwise, the method invocation is ambiguous, and a compile-time error occurs.