Wondering how Java class to Gosu IType and vise versa

363 views
Skip to first unread message

Will Hu

unread,
Feb 27, 2017, 7:21:24 AM2/27/17
to gosu-lang
Hi ,
During the gosu project that we have to do some convert between Java and Gosu.
From my understanding it is pretty much "Class<?>" and "IType"..
Wondering if we take a simple POJO as the exmaple, How I may achieve it?
BackingClass or something? Sorry I cannot find such doc online..Thanks..

Kyle Moore

unread,
Feb 27, 2017, 6:18:42 PM2/27/17
to gosu-lang
Hi Will, can I hear a bit more about your use case?

For example, in the case a Java method takes Class<?> as an argument, you can simply pass the name of a POGO. Like this:

public class Foo {
  public void takesClassAsArg(Class<?> clazz) {...}
}

You can then call it from Gosu like this:

class myPogo {}

new Foo().takesClassAsArg(myPogo)

If there's a more specific case you're encountering, please let us know.

Good luck,

- Kyle

Will Hu

unread,
Feb 28, 2017, 4:26:15 AM2/28/17
to gosu-lang
Hi Kyle,

Thanks for your update.
I was seeking the possibility like:
//Gosu POJO
class Person{
 
var name : String as Name
 
var title : String as Title
}

if I want to use a function from gson like
new Gson().fromJson(String, class)

Then I have to convert my gosu Person into a java class.
Currently I am using this way:
var ob = new Person() {:Name="Kyle", :Title="Expert"}
print(typeof(ob) as IHasJavaClass).BackingClass)

I am not sure if there is other way for this scenario..

For Java to Gosu, I am not sure how many possible ways I may try..

Thanks.


Reply all
Reply to author
Forward
0 new messages