如有个类
class A {
public native int add(int a, int b) ;
}
我们想要知道方法add的public , native 的关键字
java.lang.reflect.Modifier |
import java.lang.reflect.Method;
public static final int |
ABSTRACT |
1024 |
class Test {
public static void main(String args[]) {
Class[] clses = {int.class,int.class};
Method m = A.class.getDeclaredMethod("add", clses);
int modifers = m.getModifiers();
//1.判断是否为native
modifers = modifers %512;
modifers = modifers >> 8;
if (modifers != 1) {
System.out.println("error");
}
// 2....
}
}
public static final int |
FINAL |
16 |
public static final int |
INTERFACE |
512 |
public static final int |
NATIVE |
256 |
public static final int |
PRIVATE |
2 |
public static final int |
PROTECTED |
4 |
根据java中的定义表,按位存放的标记,参考如下
public static final int |
PUBLIC |
1 |
public static final int |
STATIC |
8 |
public static final int |
STRICT |
2048 |
public static final int |
SYNCHRONIZED |
32 |
public static final int |
TRANSIENT |
128 |
public static final int |
VOLATILE |
64 |
</script>