Java Reflection Java Java API
java.lang.reflect.Field
public void setLong(Object obj, long l) throws IllegalArgumentException, IllegalAccessException
Sets the value of a field as a long on the specified object.
long
package com.logicbig.example.field;import java.lang.reflect.Field;public class SetLongExample { private long myLong; public static void main(String... args) throws NoSuchFieldException, IllegalAccessException { Field f = SetLongExample.class.getDeclaredField("myLong"); SetLongExample instance = new SetLongExample(); f.setLong(instance, 15L); System.out.println(f.getLong(instance)); }}
15