Java same function name with different type of HashMap input variable? -
this question has answer here:
- method has same erasure method in type 6 answers
these 2 functions in same class identical names not cause error, because input variable types different. (string
, int
)
public static int samename(hashmap<integer, string> _map, string _var) { return 42; } public static int samename(hashmap<integer, string> _map, int _var) { return 42; }
in case, variable types different, still causes error. first 1 uses hashmap<integer, string>
, second uses hashmap<integer, integer>
.
public static int samename(hashmap<integer, string> _map, int _var) { return 42; } public static int samename(hashmap<integer, integer> _map, int _var) { return 42; }
why this? apart choosing different function name , flipping order of variables, there more professional ways solve this, without manipulating consistency of names of functions?
generics erased after compilation, signatures of both methods just:
int samename(hashmap, int)
change "samename" more meaningful if methods doing 2 different things.
Comments
Post a Comment