Forum: JRuby Referring to a Java Class type from Ruby

F4a55256d7dbb04f2a0287c1c64b38ea?d=identicon&s=25 Michael Chapman (kabbotta)
on 2013-12-12 04:05
I'm working on a game in libgdx, a Java library, and one of the methods
requires a reference to the type of Java class being passed.

In Java, the method is:

public <T> T get (String name, Class<T> type) {

  ...

}

And the call was:

craftWindow.setStyle(skin.get("craftWindow", WindowStyle.class));


How can I do this call in JRuby? When I pass the same string and then
WindowStyle.class it says:

no get with arguments matching [class org.jruby.
RubyString, class org.jruby.RubyClass] on object
#<Java::ComBadlogicGdxScenesSce
ne2dUi::Skin:0x1ce910e>

I've imported it with:

java_import com.badlogic.gdx.scenes.scene2d.ui.Window::WindowStyle

I'm not sure about that line either. Thanks for any help.
C983ad33b47479f17a28e083e1bb3d8b?d=identicon&s=25 Eric West (edubkendo)
on 2013-12-12 10:07
(Received via mailing list)
Try:

craftWindow.setStyle(skin.get("craftWindow".to_java,
WindowStyle.to_java.class));

Im not sure what the library is looking for here, but this may do the
trick
F4a55256d7dbb04f2a0287c1c64b38ea?d=identicon&s=25 Michael Chapman (kabbotta)
on 2013-12-12 19:00
Thanks, that seems to do the trick. I didn't even need it on the string,
just the WindowStyle class. Thanks again.
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.