Java Reflection Java Java API
java.lang.reflect.Field
public void setInt(Object obj, int i) throws IllegalArgumentException, IllegalAccessException
Sets the value of a field as an int on the specified object.
int
package com.logicbig.example.field;import java.lang.reflect.Field;public class SetIntExample { private int myInt; public static void main(String... args) throws NoSuchFieldException, IllegalAccessException { Field f = SetIntExample.class.getDeclaredField("myInt"); SetIntExample instance = new SetIntExample(); f.setInt(instance, 5); System.out.println(f.getInt(instance)); }}
5