How to get class property from class definition

245 views
Skip to first unread message

Ricardo Mayerhofer

unread,
Apr 23, 2011, 12:26:57 PM4/23/11
to gosu...@googlegroups.com
Hi all,
I'm writing a gosu project that inter-operate with regular java classes. I need to call a method that receives a Class object, but I couldn't manage to find how to get the class property from a class definition. I mean, neither of the following work:

javaMethod( MyClass.class );
javaMethod( MyClass );
javaMethod( MyClass.Type );

Is it possible? Any help is appreciated.

Thanks.

Ricardo




Carson Gross

unread,
Apr 23, 2011, 1:25:17 PM4/23/11
to gosu...@googlegroups.com
Ricardo,

You should be able to call your second form:

javaMethod( MyClass )

Gosu does not require the '.class' convention that java does in order to reference a type value.

For example, both of these work fine and print true:

print( java.lang.Object.Type.isAssignableFrom( java.lang.String ) )

// define a simple gosu class
class MyGosuClass {}

print( java.lang.Object.Type.isAssignableFrom( MyGosuClass ) )

Is MyClass a Gosu class or a Java class?

Also, what version of Gosu are you using? (If it is an earlier pre-open source version, the above code might not work.)

Cheers,
Carson

> --
> You received this message because you are subscribed to the Google Groups "gosu-lang" group.
> To post to this group, send email to gosu...@googlegroups.com.
> To unsubscribe from this group, send email to gosu-lang+...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/gosu-lang?hl=en.

Ricardo Mayerhofer

unread,
Apr 23, 2011, 1:46:28 PM4/23/11
to gosu...@googlegroups.com
Hi Carson,
Thanks for your prompt response. You're right the second form works fine. I think it's a problem with gosu eclipse plugin. It seems that the plugin is packed with an earlier version of gosu (0.7).

The compiler error shown in the IDE is:
The type "Type<simple.RequestTest>" cannot be converted to "java.lang.Class"   

Do you intend to update the eclipse plugin any time soon? It would be great (especially if it comes with JUnit suport :) ).

2011/4/23 Carson Gross <carso...@gmail.com>

Carson Gross

unread,
Apr 23, 2011, 3:23:44 PM4/23/11
to gosu...@googlegroups.com
Ricardo,

Yes, unfortunately our Eclipse plugin is pretty old.

We will be releasing an updated version of the Eclipse plugin soon (maybe in a month or so) and, shhhhhhh, don't tell anyone, an updated IntelliJ plugin as well.  Editor support is at the top of our list of priorities right now.

I'll check in with the editor guys and see about JUnit support.

Thanks for giving Gosu a shot!

Cheers,
Carson

Ricardo Mayerhofer

unread,
Apr 23, 2011, 4:21:14 PM4/23/11
to gosu...@googlegroups.com
Great to hear that. Thanks!
Reply all
Reply to author
Forward
0 new messages