Is possible to cast an array to an special class using to_java?

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 = WIN32OLE.new('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

end

Object g = container.runScriptlet(“MyClassSelector.new”);
MyClass[] lResults = container.callMethod(g , “get_list”,
MyClass[].class);

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

Antonio

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs