Given this code:
class Overloading
extends Object
{
static public void target(Object val, String chk) { System.out.println(\"Object[\"+val+\"] :: Should be
Java has always worked the same way: the "most specific" applicable overload is always chosen. Since String
is a subclass of Object
, it is "more specific", and the String
overload is chosen. If the overloads were for, say String
and Integer
, and you tried to pass null
, then you would indeed get a compile-time ambiguity error, since they are both at the same level of the same inheritance hierarchy.