Passing java classes to methods

Hi all,

I have a java method that requires one or more classes:
public class FlagBinder {
public static Module parseFlags(String[] args, Class<?>…
flagSettings)
throws ParseException {

I tried different kinds of combinations of .java_class, .to_java but
couldn’t get it working.
Java code that uses this class does this:
Module flags = FlagBinder.parseFlags(args, FlagSettings.class);

Now in ruby I tried:
flags = FlagBinder.parseFlags(args, FlagSettings.java_class)

and I get this error:
method FlagBinder.parseFlags expected [class [Ljava.lang.String;, class
[Ljava.lang.Class;]; got: [[Ljava.lang.String;,java.lang.Class]; error:
argument type mismatch (TypeError)

how can I get the expected (Ljava.lang.Class) object to pass?

Thanks,
Mathijs

On Mon, Oct 12, 2009 at 5:52 AM, Mathijs K. [email protected]
wrote:

Now in ruby I tried:
flags = FlagBinder.parseFlags(args, FlagSettings.java_class)

and I get this error:
method FlagBinder.parseFlags expected [class [Ljava.lang.String;, class
[Ljava.lang.Class;]; got: [[Ljava.lang.String;,java.lang.Class]; error:
argument type mismatch (TypeError)

JRuby in 1.4 still doesn’t automatically support Java varargs (your
Class<?>… designation), so you need to explicitly create and pass an
array like this:

[FlagBinder.java_class].to_java(java.lang.Class)

I had hoped to fix it so the .java_class part wouldn’t be needed in
1.4, but it slipped.

  • Charlie

To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email