Field setDouble() method in Java with Examples
setDouble() method of java.lang.reflect.Field used to set the value of a field as a double on the specified object. When you need to set the value of a field of an object as double then you can use this method to set value over an Object.
public void setDouble(Object obj, double d) throws IllegalArgumentException, IllegalAccessException
Parameters: This method accepts two parameters:
- obj: which is the object whose field should be modified and
- d: which is the new value for the field of obj being modified.
Return: This method returns nothing.
Exception: This method throws the following Exception:
- IllegalAccessException: if this Field object is enforcing Java language access control and the underlying field is either inaccessible or final.
- IllegalArgumentException: if the specified object is not an instance of the class or interface declaring the underlying field (or a subclass or implementor thereof), or if an unwrapping conversion fails.
- NullPointerException: if the specified object is null and the field is an instance field.
- ExceptionInInitializerError: if the initialization provoked by this method fails.
Below programs illustrate setDouble() method:
Value of salary before applying setDouble is 43125.0 Value of salary after applying setDouble is 50000.99 Value of pf before applying setDouble is 2342.89 Value of pf after applying setDouble is 1234.34
Value after applying setDouble is 53245.466