On 2008.05.13., at 15:52, helge wrote: > Hi, > > just walked over something again which keeps annoying me :-) > > If there are Java methods like: > isNotEmpty(Object _o) > isNotEmpty(String _s) > > which are called by Rhino like this: > isNotEmpty(null) > > an exception is thrown that Rhino can't decide for a signature > (because null could be either). > > I can follow the reasoning but IMHO it would be more convenient to > defer to the type highest in the class hierarchy (isNotEmpty(Object) > in this case). If there are multiple paths, choose the first or so.
Which wouldn't match Java behaviour :-) > > > Its technically not 100% correct, but IMHO the situation that someone > has methods with the same name but different behavior is much less > likely than the other way around. > In fact I just checked Java. It doesn't complain, but actually invokes > isNotEmpty(String). Weird, does someone know why? :-) Sure. The compiler always chooses the most specific of all applicable methods. Both (Object) and (String) are applicable to (null), but (String) is more specific, because String extends Object. If you had a third override, i.e. isNotEmpty(Integer), you'd get a compiler error as both (Integer) and (String) would be applicable, but neither is more specific than the other. Attila. _______________________________________________ dev-tech-js-engine-rhino mailing list [email protected] https://lists.mozilla.org/listinfo/dev-tech-js-engine-rhino
