Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.

Tip of the Day
Language: Java
Expertise: Intermediate
Aug 21, 2006



Application Security Testing: An Integral Part of DevOps

Using the java.lang.reflect.Modifier Class

You know that you can extract constructors, methods, and variables from a Java class file. Generally, when you use

	Field fields[] = c.getDeclaredFields( );
where c is initialized using

	Class c = Class.forName(className);
and print the fields array, you get all the elements declared in the class.

However, suppose you want to restrict the output to all fields other than those declared as private. In this case, you would use the following code, where the Modifier class is a part of the java.lang.reflect package:

if(!Modifier.isPrivate(fields[i].getModifiers( )){
Using Modifier.isPrivate() ensures that the private variables are not printed.

The same can be used for methods as well.

MS Sridhar
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date