adamdruppe / arsd

This is a collection of modules that I've released over the years. Most of them stand alone, or have just one or two dependencies in here, so you don't have to download this whole repo.
http://arsd-official.dpldocs.info/arsd.html
531 stars 128 forks source link

jni.d inheriting from java interfaces #372

Open John-Colvin opened 1 year ago

John-Colvin commented 1 year ago

Is this possible? Just noticed interfaces and classes are all translated asfinal class 😱 and there's a comment saying

    // so overriding Java classes from D is iffy and with separate implementation
    // non final leads to linker errors anyway...

so maybe this is a genuinely hard problem?

adamdruppe commented 1 year ago

I know on Android it was just plain impossible to generate new classes through JNI, so I dropped it, but with regular Java it would be possible, in theory, to generate some Java bytecode that has a stub class forwards to a D class and subclass things that way. But yeah, it is easier said than done.

The best way to use this is to call Java methods from D and then write little Java classes in Java with native methods you implement on the D side. This makes doing things like callbacks a pain since all those delegate classes will need Java stubs.