Java Field.setLong(Object obj, long l)

Syntax

Field.setLong(Object obj, long l) has the following syntax.

public void setLong(Object obj,  long l)  throws IllegalArgumentException ,   IllegalAccessException

Example

In the following code shows how to use Field.setLong(Object obj, long l) method.


import java.lang.reflect.Field;
//  ww  w . j a  v a2  s .c om
class MyClass {
  public long i = 99999999L;
}

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.getLong(x));
    
    f.setLong(x, 9L);
    System.out.println(f.getLong(x)); 

  }
}

The code above generates the following result.





















Home »
  Java Tutorial »
    java.lang.reflect »




Array
Constructor
Field
Method
Modifier
ParameterizedType
TypeVariable