cretz / software-ideas

88 stars 0 forks source link

Kotlin Easy-JNI #73

Open cretz opened 6 years ago

cretz commented 6 years ago

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
    }
}