Home Java Reflect Finding out the class fields
Questions:Ask|Latest


 
 

Share on Google+Share on Google+

Finding out the class fields

Advertisement
This section explores you, how to retrieve the fields of the class by using the getFields() method. For this we are taking an example that provides the use of the getFields() method in detailed way.

Finding out the class fields

     

This section explores you, how to retrieve the fields of the class by using the getFields() method. For this we are taking an example that provides the use of the getFields() method in detailed way.

Create a class "Ffield" and create an object of this class and assign it the reference of java.util.Integer.class class. Now retrieve the class fields by using the getFields() method.

Here is the code of the Example :

Ffield.java:

import java.lang.reflect.*;

public class Ffield{
  public static void main(String[] args){
  Class cls = java.lang.String.class;
  Field field = cls.getFields()[0];
  String name;
  name = field.getName()// It'll show CASE_INSENSITIVE_ORDER
  System.out.println(name);
  }
}

Here is the output of the Example :

C:\roseindia>javac Ffield.java

C:\roseindia>java Ffield
CASE_INSENSITIVE_ORDER

Download this Example:

Advertisement

Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: February 28, 2008

Ask Questions?    Discuss: Finding out the class fields  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
DMCA.com