which to me seems like overloading the returning
type. It would be great if something like this could
be done in Java
it can be:
[/code]
public void myMethod() {
if (...) {
return new Integer(0); //or only 0 with JDK 1.5
} else {
return "a string";
}
[/code]
Now that is definitely an awsome thing to do, because what good common use would you have for a number and a string? They obviously mean different things.
Some other languages support the overloading based on the return type.
Something like this could be conveivable:
class Pondering {
public Integer tell() { /...
}
public String tell() / /...
}
void foo() {
Integer I = tell(); // can be resolved
String s = tell(); // can be resolved
Object o = tell(); // out of luck here
}
}
So, why not just allow method overloading based on return types when the return type is a primitive?
int i = getProperty(key);
boolean flag = getProperty(key);
instead of
int i = getProperty_int(key);
boolean flag = getProperty_boolean(key);
That'd be nice. Even nicer would be to allow return type method overloading across the board, but throw an error or a warning at compile time if method usage was ambiguous.
String str = getProperty(key);
Integer val = getProperty(key);
Object o = getProperty(key); // ERROR! WARNING! Ambiguous method invocation! (Me stupid compiler and me don't know which one you mean!)
Unless, GASPS, there were a
public Object getProperty(String key) {returnnull;}
defined somewhere. I'm sure this entire issue has already been debated to death elsewhere. Pointers? Links?