java - Duplicate Method while Method-Overloading -


following code gives compilation error error "duplicate method"

static int test(int i){      return 1; }  static string test(int i){      return "abc"; } 

this expected both overloaded method have same signature , differ in return type.

but following code compiles fine warning:

static int test1(list<integer> l){     return 1; }  static string test1(list<string> l){     return "abc"; } 

as, know java generics works on erasure, mean in byte-code, both these method have same signature , differs return type.

furthur, surprise following code again gives compilation error:

static int test1(list<integer> l){     return 1; }  static string test1(list l){     return "abc"; } 

how second code working fine without giving compilation error, though there duplicate method?

resolving overloaded methods done @ compile-time, rather runtime, java compiler know difference between 2 in second example. in third example, problem list<integer> list, wouldn't know 1 use if passed in list<integer>.


Comments

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -