Get and Set int typed Field value in Java
Description
The following code shows how to get and Set int typed Field value.
Example
/*from www. jav a 2 s. c o 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");
// Get value of a static field
System.out.println(field.getInt(null));
// Set value of a static field
field.setInt(null, 123);
System.out.println(field.getInt(null));
}
}