i have a question to Java Overload Methods.
Suppose i have an overload methods foo:
public static String foo(String x) {
return "foo-String: " + x;
}
public static String foo(Object x) {
return "foo-Object: " + x;
}
How can I implement to functions like
public static String useString() {
return(foo("useString"));
}
public static String useObject() {
return(foo("useObject"));
}
of which one uses the overloaded string method, and one the overloaded object method?
The call of the foo-Method should use an String input. (that means i do not want to work with a cast like
return(foo((Object)"useObject"));
Maybe you can help me with this problem
EDIT:
Above, just is an example for an exercise. I am trying to understand Overloads and Dispatch better and was looking for alternative solution for calling (and selecting) an overload method.