I am rewriting some native methods as regular Java methods.
Are native methods effectively static? Or is there ever a case where they have an implicit 'this' parameter?
Thanks!
A Java method is generically a code block with a name that you can write using plain java. A native method is a method that is linked to a native library.
Native methods are Java™ methods that start in a language other than Java. Native methods can access system-specific functions and APIs that are not available directly in Java. The use of native methods limits the portability of an application, because it involves system-specific code.
You can use the full power of inheritance and overriding since your methods are no longer static. You can use the constructor to do any initialisation, including associating SQL with the table (SQL that your methods can use later). This should make all your problems above go away, or at least get much simpler.
That's because static methods can't access the object's attributes. Static methods aren't part of the object, so they don't have access to anything that belongs to the object.
Native methods can be static
or non-static
, just like regular Java methods.
Non-static
native methods receive this
reference, static
ones receive a reference to containg class instead.
From JNI Specification:
Native Method Arguments
The JNI interface pointer is the first argument to native methods. The JNI interface pointer is of type JNIEnv. The second argument differs depending on whether the native method is static or nonstatic. The second argument to a nonstatic native method is a reference to the object. The second argument to a static native method is a reference to its Java class.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With