Suppose you have overloaded methods that take one parameter, and you want to call one of them and pass null to it.
public void method1 (String param) {}
public void method1 (StringBuilder param) {}
If you call
method1 (null);
the code will not pass the compilation, since both methods accept the link null, and the compiler has no preference between two overloads.
If you call
method1 ((String) null);
the first method will be called.
If you call
method1 ((StringBuilder) null);
the second method will be called.
source
share