Retrieve Modifier Information using Java Reflection APIs

Java Reflection has API called getModifiers() which is used to get Modifier information of class. just create object of class and call getModifiers() method. Play with Modifier and it's methods.

Java Program to get Modifier Information using Java Reflection API:

System.out.println("Modifier Information - ");
List list = new ArrayList();
Class originalClassObj = list.getClass();
int modifier = originalClassObj.getModifiers();
if (Modifier.isPublic(modifier)) {
 System.out.println("public");
}
if (Modifier.isAbstract(modifier)) {
 System.out.println("abstract");
}
if (Modifier.isFinal(modifier)) {
 System.out.println("final");
}
Output :

Modifier Information - 
public


No comments:

Post a Comment