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.

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.

Finding out the class fields

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: