Using Java Reflection, you can detect all methods and their returns type. But is there a way to detect if a method is declared as native or not?
Yes you can.The method getModifiers() returns an int which applied the right mask can tell you if the method is native or not
I would suggest doing it like this, for convenience:
int modifiers = myMethod.getModifiers();
boolean isNative = Modifier.isNative(modifiers);
The Modifier class is an utility specialized class meant to apply the appropriate masks in order to discover the modifiers of the method.
Method has a getModifiers() method which returns the modifiers as an int, and one of the modifiers is Modifier.NATIVE, which is what your looking for. Modifier.isNative() can be used to decode the argument from getModifiers().
(Basically, if you have your method as a Method object named m, then Modifier.isNative(m.getModifiers()) should do it.)
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