Field.getFloat(Object obj) has the following syntax.
public float getFloat(Object obj) throws IllegalArgumentException , IllegalAccessException
In the following code shows how to use Field.getFloat(Object obj) method.
import java.lang.reflect.Field; /*from w w w . j a v a2 s .c om*/ class MyClass { public float i = 1.123F; } public class Main { public static void main(String[] args) throws Exception { Class<?> clazz = Class.forName("MyClass"); MyClass x = (MyClass) clazz.newInstance(); Field f = clazz.getField("i"); System.out.println(f.getFloat(x)); f.setFloat(x, 9.99F); System.out.println(f.getFloat(x)); } }
The code above generates the following result.