Java Method.getModifiers()
Syntax
Method.getModifiers() has the following syntax.
public int getModifiers()
Example
In the following code shows how to use Method.getModifiers() method.
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
//www . j a v a 2 s.c om
public class Main{
public static void main(String[] args) {
Method[] methods = java.lang.Integer.class.getDeclaredMethods();
for (int i = 0; i < methods.length; i++) {
Method m = methods[i];
Class retType = m.getReturnType();
Class[] paramTypes = m.getParameterTypes();
String name = m.getName();
System.out.print(Modifier.toString(m.getModifiers()));
System.out.print(" " + retType.getName() + " " + name + "(");
for (int j = 0; j < paramTypes.length; j++) {
if (j > 0)
System.out.print(", ");
System.out.print(paramTypes[j].getName());
}
System.out.println(");");
}
}
}
The output: