On 2008.05.13., at 17:36, helge wrote: > Why would you call the most specific variant? Since null is most > generic, I would expect the most generic method to be called :-)
Well, that's the algorithm javac uses to choose among overloads at compile time, and it's part of the Java Language Specification. Don't get me wrong, I'm not trying to refer to authority here -- you're free to debate it or point out that it might be unintuitive from your POV. I think JLS or no JLS, it does make perfect sense. Also, if null literal in argument list was handled as a special case and would match most generic type, and other values would match most specific, that'd pose some interesting resolution problems with overloads that have more than one argument, and you pass null for some arguments. > > Anyways. > >> And what additional type knowledge does Rhino have about null at >> runtime? > > It knows that the value is actually null when it decides for a method > to call? Java doesn't know that when it chooses the method to be > invoked, it only has the static type at compile time (ignoring the > special case of a constant 'null'). Right - that's true. With dynamic invocation, the overloaded method selection happens at invocation time. I thought you're still debating the special case of null literal here :-) >>> So are there chances that this is added to Rhino? :-) >> Hm... Rhino is supposed to have overloaded method resolution, isn't >> it? > > Apparently not (btw: those are just static functions, not > constructors): > ---snip--- > Message: The choice of Java constructor isNotEmpty matching JavaScript > argument types (null) is ambiguous; candidate constructors are: > boolean isNotEmpty(java.lang.Object) boolean > isNotEmpty(java.lang.String) > ---snap--- Hm... that's bad. Norris -- if you're listening -- are you or anyone else aware of the degree Rhino is supposed to support resolution of overloaded Java methods? Attila. _______________________________________________ dev-tech-js-engine-rhino mailing list [email protected] https://lists.mozilla.org/listinfo/dev-tech-js-engine-rhino
