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
Post a Comment