If the cast where not performed, then the most specific version would be chosen.
null
could be a null-reference of type String
or of type Object
. So if those two methods are available, then the String
method will be called.
If you have methods with Object
, Integer
and String
then calling that with null
(and no cast) would give a compilation error because Integer
and String
are both valid and equally specific (i.e. none is a specialization of the other). In that case you would have to cast null
to specify which method to call.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…