开发者

Using Interfaces in JNI

开发者 https://www.devze.com 2022-12-24 09:56 出处:网络
开发者_如何学编程I am trying to use (*env)->RegisterNatives to add methods to a defined class which I then add to a callback list.
开发者_如何学编程

I am trying to use (*env)->RegisterNatives to add methods to a defined class which I then add to a callback list. The callback sender of course expects my class to implement a certain interface which I do not. And is failing on execution.

If I add the keyword "implements Listener" to my class in Java the javac expects to have the methods definition in Java or with native keyword which I try to avoid here, as I'd like to register the methods within the JNI_OnLoad and execute one of them afterwards.

The question now is: Can I implement the interface in JNI or avoid the error message in Java?


RegisterNatives doesn't add new native methods, it registers native function for the existing native method in the class. If someone doesn't call RegisterNatives for a native method, the JVM will search all DLL libraries for its implementation when method is called for the first time.

So, add implements Listener, write definitions with native keyword and register their implementation with RegisterNatives.

0

精彩评论

暂无评论...
验证码 换一张
取 消