Using Java constructors with lime.system.JNI


#1

Hi guys,

I tried to get the constructor of this Java class like this:

constructor = JNI.createMemberMethod("io.socket.client.IO$Options", "<init>", "()V");

No crash so I assumed it’s going well. But how do I use it? I have been wrapping all the construction in Java methods but now I’m starting to think how nice it would be if I can use the constructors directly.

Thank you.


#2

I think that constructor() would return a new instance of the class, I believe.

If you wanted to use it like a Haxe class, short of targeting the Java target for Haxe, I think it would be necessary to wrap it, so new for your wrapper class creates a JNI instance internally, then you could wrap other calls using getter/setters, just be aware certain calls would have to be wrapped in handlers to make sure it occurs on the proper thread


#3

Hi singmajesty. Thank you for the tips! :smiley:

I just realized I used createMemberMethod instead of createStaticMethod so it crashed whenever I tried calling constructor(). :man_facepalming: