Forum: JRuby is possible to cast an array to an special class using to_java ?

87f380c90154a04d83a3ce78ec35c878?d=identicon&s=25 Antonio Castellon (antonio_c66)
on 2013-09-24 14:28
Dear Developers,

I see that is possible to acquire from Java an Array of a predefined
type of Objects like ( java.lang.String, etc...) ..but in the same way I
can do this?

class MyClass
   private int x;

   public int getX() { return x; };
   public void setX(int x1) { x = x1; };


 require 'java'
 java_import 'MyClass'

 def get_list

      # calling elements in DLL

      dll3 ='MyWrapperDLL.Core') # from C#
      results = dll3.execute()

      # results contains the same class structure into the DLL
      # than in Java Class object defined.
      # I can print the data contained in the result using
      # overrided toString() method in Java Class ithout problems

      return results


  Object g = container.runScriptlet("");
  MyClass[] lResults = container.callMethod(g , "get_list",


I'm trying to do it in elegant way (without create each Object defined
in the returned Array from the DLL into the Ruby code in another Java
Array with this objects.)

It's possible or I'm dreaming?

At the moment my test always return to me an "array element type
mismatch" exception when the callMethod is called.

Thanks in advance

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.