When I run this program why it is calling method overloaded with string parameter.
public class StaticBindTest {
public static void main(String args[]) {
StaticBindTest et = new StaticBindTest();
et.sort(null);
}
//overloaded method
public void sort(Object c){
System.out.println("Inside Collection sort method");
}
//another overloaded method
public void sort(String hs){
System.out.println("Inside HashSet sort method");
}
}
In case if I re-write my method as
public void sort(String hs){
if(hs instanceof String)
System.out.println("Inside HashSet sort method");
}
It will display blank console, which means it is not a instance of String then why it call in this manner?