java - What decides whether a static or object method should be called -


just general query came accidentally giving variable of 1 class name matched class both had method of same name, 1 of static.

given following:

public class {     public static string dothis(string string){         return "class";     }      public static string dothis(string string, string string2){         return "class method 2";     } } 

and this

public class b {         public string dothis(string string){         return "object";     } } 

is following call object , not static method once object instantiated?

system.out.println(a.dothis("..."));//outputs class b = new b(); system.out.println(a.dothis("..."));//outputs object 

n.b. following instantiation appears impossible call static methods in class a, i.e.

b = new b(); system.out.println(a.dothis("...")); system.out.println(a.dothis("...","..."));//won't compile 

the above won't compile complaining erroneous tree type,

edit: added specific exception :-

java.lang.runtimeexception: uncompilable source code - erroneous tree type: <any>     @ testbed..... 

... mean compiler deciding method call, difference javac version may behave differently.

what going on here , if guaranteed used obfuscation in way, or decompilation remove name clash?

after doing this:

b = new b(); 

... identifier a refers variable, not class.

to avoid being problem, don't that...

what going on here , if guaranteed used obfuscation in way, or decompilation remove name clash?

that entirely depends on decompiler. if it's smart enough recognize issue, rename local variable 1 doesn't clash.


Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -