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

c++ - Function signature as a function template parameter -

algorithm - What are some ways to combine a number of (potentially incompatible) sorted sub-sets of a total set into a (partial) ordering of the total set? -

How to call a javascript function after the page loads with a chrome extension? -