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

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
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

This topic is locked and can not be replied to.