Java same function name with different type of HashMap input variable? -


this question has answer here:

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

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -