These two functions in the same class with identical names does not cause an error, because the input variable types are different. (String
and 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 this case, the variable types are also different, still this causes an error. The first one uses a HashMap<Integer, String>
, the 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 is this? Apart from choosing a different function name and flipping the order of variables, are there any more professional ways to solve this, without manipulating the consistency of the names of my functions?