Reflection Java Book

String toGenericString()
Returns a string describing this Field, including its generic type.
String toString()
Returns a string describing this Field.
Revised from Open JDK source code
The following code gets and sets the values of instance and class fields

import java.lang.reflect.Field;
class X {
public int i = 10;
public static final double PI = 3.14;
}
public class Main {
public static void main(String[] args) throws Exception {
Class clazz = Class.forName("X");
X x = (X) clazz.newInstance();
Field f = clazz.getField("i");
System.out.println(f.getInt(x)); // Output: 10
f.setInt(x, 20);
System.out.println(f.getInt(x)); // Output: 20
f = clazz.getField("PI");
System.out.println(f.getDouble(null)); // Output: 3.14
f.setDouble(x, 20);
}
}

10
20
3.14
Exception in thread "main" java.lang.IllegalAccessException: Can not set static final double field X.PI to (double)20.0
at sun.reflect.UnsafeFieldAccessorImpl.throwFinalFieldIllegalAccessException(UnsafeFieldAccessorImpl.java:55)
at sun.reflect.UnsafeFieldAccessorImpl.throwFinalFieldIllegalAccessException(UnsafeFieldAccessorImpl.java:91)
at sun.reflect.UnsafeQualifiedStaticDoubleFieldAccessorImpl.setDouble(UnsafeQualifiedStaticDoubleFieldAccessorImpl.java:141)
at java.lang.reflect.Field.setDouble(Field.java:889)
at Main.main(Main.java:18)