java - Dilemma with overloaded method selection -


public void testfunc(object o) {      system.out.println("testfunc-object"); }  public void testfunc(string s) {      system.out.println("testfunc-string"); } 

both of these methods in test class. if invoke following method main method of test class, method invoked?

test t = new test(); t.testfunc(null); 

in particular scenario, testfunc(string) called, why? appreciate help.

testfunc(string s) gets invoked because runtime choose variant of testfunc specific argument. testfunc(string s) more specific testfunc(object o) because string subtype of object.

peruse section 15.12.2.5 of jls explicit details.


Comments

Popular posts from this blog

How can I edit my VIM config so that Vim treats ".ejs" files the same as it currently treats my html files? -

Python __call__ special method practical example -