Java Field.getFloat(Object obj)
Syntax
Field.getFloat(Object obj) has the following syntax.
public float getFloat(Object obj) throws IllegalArgumentException , IllegalAccessException
Example
In the following code shows how to use Field.getFloat(Object obj) method.
import java.lang.reflect.Field;
//from ww w .ja v a 2 s.c o m
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.