There was a question last night after my talk regarding how JRuby
handles Java methods called from Ruby that are overloaded. Here's an
excerpt of what the JRuby book says:

***
Let’s say you’re attempting to call the foo method on class X. First,
JRuby will use Java reflection to search for all public and protected
methods named foo for X and its superclasses. Child classes’ methods
override their parents’, just as in pure Java. Next, JRuby narrows
down the list to just the methods that match the number of arguments
you’re passing in, including methods with variable argument lists.

When there’s more than one matching overload, JRuby looks for the best
fit based on the passed-in parameters. Types that map directly between
Ruby and Java get preferential treatment. For instance, Ruby Fixnums
match Java integer types (both primitive and boxed), Ruby strings
match Java strings, and so on.

If no direct mappings exist, JRuby tries a looser fit by converting
between different numeric types. For a Ruby Integer with no
corresponding Java int or Integer argument, JRuby will look for a Java
Numeric. As a last resort, JRuby looks for parameters that are Java
interfaces and attempts to implement those interfaces on the fly.
***

There you have it!



Chris

-- 
SD Ruby mailing list
[email protected]
http://groups.google.com/group/sdruby

Reply via email to