Creating Java array of Classes

Hi,

I’m trying to use Java’s (1.6) URLConnection with JRuby and all has gone
well except when I’m trying use the getContent method.

The method signature is “getContent(Class[] classes)” as it needs to
know the class type to convert the response too.

However I try to create the required array of type class (I only need
one element that’s a java string class) it complains and refuses to take
the array I’ve given.

The closest I’ve got is…

    class_array = Array.new
    class_array << JavaLang::String.class
    java_class_array = class_array.to_java JavaLang::String.class
    content = connection.get_content java_class_array

Which generates the following error…
unable to convert array to type: Class

I’ve run out of ideas as too how to create the array needed.

Any ideas or help to get around this would be greatly appreciated.

Cheers, Phil

On Sat, Jan 16, 2010 at 2:23 PM, Phil O. [email protected]
wrote:

The closest I’ve got is…

    class_array = Array.new
    class_array << JavaLang::String.class
    java_class_array = class_array.to_java JavaLang::String.class
    content = connection.get_content java_class_array

Which generates the following error…
    unable to convert array to type: Class

Try this:

âž” jruby -rjava -e “p ([java.lang.String].to_java java.lang.Class)”
[Ljava.lang.Class;@35e6e3

And avoid the JavaLang-style package modules; they’re subject to
change and kind of deprecated.

  • Charlie

To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

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