使用Java Reflection,您可以检测方法是否为Native? [英] Using Java Reflection, can you detect if a method is Native or not?

查看:242
本文介绍了使用Java Reflection,您可以检测方法是否为Native?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Java Reflection,您可以检测所有方法及其返回类型。但有没有办法检测方法是否被声明为 native

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?

推荐答案

是的你可以。方法 getModifiers()返回一个应用了右掩码的int可以告诉你方法是否是本机的

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);

Modifier类是一个实用程序专用类,用于应用适当的掩码以发现修饰符方法。

The Modifier class is an utility specialized class meant to apply the appropriate masks in order to discover the modifiers of the method.

这篇关于使用Java Reflection,您可以检测方法是否为Native?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆