Now that we know it's quite trivial to use Kotlin with JNI, how about making the interaction easier? For example, in Kotlin Native:
package somepkg
@ExposeJNI
class Foo {
fun bar() = "baz"
}
That will create a bridge method of Java_somepkg_Foo_bar and methods for create and finalize. Generate, in Kotlin:
class Foo {
private val ptr: Long
init { ptr = createNative() }
external fun bar(): String
protected external override fun finalize()
companion object {
private fun createNative(): Long
}
}
Obviously can only expose primitives, strings, other native objects, and arrays of those last three
JNI bridge methods do the conversion
Native method created to create the object, and finalize is a native
While native classes may be marked open (e.g. @ExposeJNI(open = true)), they themselves extend from nothing even if they do in the native side
Public and protected methods and properties can be exposed
Now that we know it's quite trivial to use Kotlin with JNI, how about making the interaction easier? For example, in Kotlin Native:
That will create a bridge method of
Java_somepkg_Foo_bar
and methods for create and finalize. Generate, in Kotlin:@ExposeJNI(open = true)
), they themselves extend from nothing even if they do in the native side