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

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -