|
Thanks Bill. It's better than writing in straight Java and this is a good enough work around.
I think jruby should provide a standard mechanism that works in all cases (class and instance methods). This workaround does not work. I checked JRuby 1.1.2 and 1.1.3.
irb(main):046:0> pool.class irb(main):047:0> init_method = pool.java_class.java_method :initialize irb(main):048:0> init_method.invoke(Java.java_to_ruby(pool)) OK, guys. I have the solution.
class Java::JavaLang::Object
Tescior.new.java_call :initialize It is necessary to pass parameter types because knowing method name is not enough to pick up the methods. Java uses method overloading. JRuby does not distinguish between int and Integer. Look at third and forth method below. public class Tescior { I realy like the last commenters solution. I will write it in Java and change the name from 'java_call' to 'java_send' to mirror 'send' (makes it easier for Rubyists to remember).
We ended up fixing this differently than outlined above. The new synax is to use 'send' and to suffix your method name with $method. So:
public class Foo {
public String initialize() { return "foo"; }
}
In Ruby:
Foo.new.send("initialize$method") # returns "foo"
Future versions JRuby will allow targeting specific signature methods through similiar name-mangling (though not for 1.1.6). Oops. After the fact realization that if anyone tries to call 'initialize$method directly instead of via send we will call intiailize with the value of $method (bound to be nil). FAIL!
New method is __method as suffix. This has an extremely slight possibility of name conflict (very extremely), but it is directly callable: public class Foo {
public String initialize() { return "foo"; }
}
In Ruby:
initialize__method # returns "foo"
|
|||||||||||||||||||||||||||||||||||||||||||||||
I've been meaning for a while to implement a java_call method that works like this:
Args and the result would be converted automatically.
Comments?