Java - why no return type based method overloading?
Solution 1:
Because you are not required to capture the return value of a method in Java, in which case the compiler can not decide which overload to use. E.g.
boolean doSomething() { ... }
int doSomething() { ... }
doSomething(); // which one to call???
Solution 2:
One interesting aspect about this question is the fact that the Java language forbids overloading methods only by return type. But not the JVM:
Note that there may be more than one matching method in a class because while the Java language forbids a class to declare multiple methods with the same signature but different return types, the Java virtual machine does not. This increased flexibility in the virtual machine can be used to implement various language features. For example, covariant returns can be implemented with bridge methods; the bridge method and the method being overridden would have the same signature but different return types.
From: Class.getMethod(String, Class...)