|
|
Re: Scripting for the Java Platform
|
Posted: Jul 27, 2006 3:31 PM
|
|
> There has always been a trade-off between the safety of > static type-checking and user flexibility. If we could > allow methods to be overridden not merely on the basis of > the types of input arguments, but also by result returned, > a typed language could have the same benefits. > Unfortunately, static type checking may not be possible > e with this kind of polymorphism. > If I remember my reading of the JVM spec, that kind of overriding is possible at the class file level, because methods are described with method "descriptors," which include the return type, as opposed to method "signatures," that exclude the return type. My understanding was that the main reason you can't overload on return type in Java (or C++ for that matter) was that at the source level, when invoking a so-overloaded method without using the return type, the compiler wouldn't be able to figure out which overloaded option you meant.
|
|