Java Field.setDouble(Object obj, double d)

Syntax

Field.setDouble(Object obj, double d) has the following syntax.

public void setDouble(Object obj,  double d)  throws IllegalArgumentException ,   IllegalAccessException

Example

In the following code shows how to use Field.setDouble(Object obj, double d) method.


import java.lang.reflect.Field;
/* w  w  w  .j  a v  a2 s . c om*/
class MyClass {
  public double i = 1.123;
}

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.getDouble(x));
    
    f.setDouble(x, 9.99);
    System.out.println(f.getDouble(x)); 

  }
}

The code above generates the following result.





















Home »
  Java Tutorial »
    java.lang.reflect »




Array
Constructor
Field
Method
Modifier
ParameterizedType
TypeVariable