I’m having problems getting the Java <-> Ruby integration to work in
jRuby
1.4.0 and signed up to the list in order to tap into the more
experienced
crowd.
When I try to cast a new instance of the jruby-generated java object
into a
Java interface which that object implements I’m getting
ClassCaseException.
If anyone could point out what I’m doing wrong I’d be extremely
grateful.
The following test case should work unless I’ve misunderstood the
examples
Charles and Vladimir have posted elsewhere on the web:
package org.test;
import javax.script.ScriptEngineManager;
public class Runner {
public static interface Interface { }
public static Class<? extends Interface> RClass;
static String getRubySource() {
return
" require 'jruby/core_ext' \n" +
" class RubyClass \n" +
" include org.test.Runner::Interface \n" +
" end \n" +
" org.test.Runner.RClass = RubyClass.become_java! \n";
}
public static void main(String[] args) throws Exception {
new ScriptEngineManager()
.getEngineByName("jruby")
.eval(getRubySource());
/* Will throw a ClassCastException, why? */
Interface object = RClass.newInstance();
}
}