Java Reflection Java Java API
java.lang.reflect.Field
public void setFloat(Object obj, float f) throws IllegalArgumentException, IllegalAccessException
Sets the value of a field as a float on the specified object.
float
package com.logicbig.example.field;import java.lang.reflect.Field;public class SetFloatExample { private float aFloat; public static void main(String... args) throws NoSuchFieldException, IllegalAccessException { Field f = SetFloatExample.class.getDeclaredField("aFloat"); SetFloatExample instance = new SetFloatExample(); f.setFloat(instance, 1.5f); System.out.println(f.getFloat(instance)); }}
1.5