arsd icon indicating copy to clipboard operation
arsd copied to clipboard

jni.d inheriting from java interfaces

Open John-Colvin opened this issue 2 years ago • 1 comments
trafficstars

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?

John-Colvin avatar Mar 02 '23 15:03 John-Colvin

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.

adamdruppe avatar Mar 02 '23 15:03 adamdruppe