Obtain a particular Field object in Java

Description

The following code shows how to obtain a particular Field object.

Example


//from  ww w .jav a2s. co m
import java.lang.reflect.Field;

public class Main {
  public static void main(String[] argv) throws Exception {

    Class cls = java.awt.Point.class;

    Field field = cls.getField("x");
    System.out.println(field);
  }
}

The code above generates the following result.





















Home »
  Java Tutorial »
    Reflection »




Annotation
Array
Class
Constructor
Field
Generics
Interface
Method
Modifier
Package
Proxy