Forum: JRuby Converting Ruby objects to Java using to_java

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Pranav S. (Guest)
on 2008-12-30 00:45
Hi, I'm new to JRuby and I have a question regarding passing ruby
variables to java.

Situation:
In java, I have an abstract class, called JClassA and another class
called JClassB.
In ruby, I implement the concreate class of JClassA, called RClass.

Here are the relations:

RCLass < JClassA.
JClassB(JClassA) (The constructor of JClassB takes JClassA as an
argument)

Problem:
From RClass, I need to call JClassB and give the current instance as an
argument.

If I do JClassB.new(self), then it will complain about not finding the
constructor.

On the other hand, if I do
JClassB.new(self.to_java(Java::SomePackage.JClassA)) then it complains
that it cannot find the method to_java in RClassB.

What am I doing wrong? Can I convert any ruby object to java object?

Thanks,
Pran.
Pranav S. (Guest)
on 2008-12-30 18:50
Figured it out.

You cannot send a reference of 'self' from the 'initialize' method.
This topic is locked and can not be replied to.